public class ChatAgent extends Agent implements ChatAgentInterface
ChatAgent
is a simple subclass of Agent
designed to be used with a GUI as a chat or message system. Each user has their own ChatAgent
and each cooperation domain is treated as a separate "chat room". A history of messages is stored, each message represented by a ChatMessage
. The public functions of this class are outlined in the interface ChatAgentInterface
. Agent
, this agent can originate the following messages types: performative | act | see | reply handler |
---|---|---|---|
- |
Agent
, this agent responds to the following messages types: performative | act | see |
---|---|---|
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
ChatMessage
,
ChatAgentInterface
TransientAgent.NewAgentLispCommand
AbstractProcess.Subthread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
private Hashtable<URLDescriptor,Vector<ChatMessage>> |
cooperationDomainHistories
A
Hashtable linking the URLDescriptor of a
cooperation domain to a Vector of the message history
(ChatMessage s) of that cooperation domain. |
protected URLDescriptor |
currentCD |
private boolean |
obtainHistory
A boolean value that determines if the agent will retrieve the history of
a cooperation domain whenever it joins it.
|
private boolean |
setObtainHistory |
agentConstructorComplete, properties
cacheKB, CDInvitedTo, CDinvitee, conversationData, defaultOntologyClassName, DEFER_ACTION, DROP_ACTION, kBase, ListOfArgs, ontologyEngineCreateMethod, ontologyEngineLoadMethod, policies, policiesAlwaysApply, policiesLastResort, primaryUI, proxy, UIs, usingProxy
huntForPort, initParams, ontology, ontologyShared, options, securityFilter, trace, TRACE_MONITOR, TRACE_OFF, TRACE_ON, TRACE_TO_FILE, TRACE_UNDEFINED, uniqueThreadName, waitingForAgentToStart
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
ChatAgent(ParamsMap params,
AgentUI ui)
Creates a new
ChatAgent on the given port, with the given
name, registered with the LAC on the given port. |
Modifier and Type | Method and Description |
---|---|
PerformDescriptor |
accept_chat_message(MLMessage message)
Handler for a message with the performative inform, and the act
chat.message.
|
protected PerformDescriptor |
accept_time(MLMessage message) |
boolean |
canObtainHistory() |
void |
chatMessage(URLDescriptor cd,
MLMessage message)
Performs operations necessary when a chat message has been received.
|
Status |
doSendChatMessage(URLDescriptor cd,
List<URLDescriptor> to,
boolean whisper,
String message)
Sends the given chat message through the given cooperation domain to the
given agents.
|
Status |
doSendChatMessage(URLDescriptor cd,
String message)
Sends the given chat message through the given cooperation domain to all
current members of that cooperation domain.
|
Status |
doSendChatMessage(URLDescriptor cd,
URLDescriptor to,
boolean whisper,
String message)
Sends the given chat message through the given cooperation domain to the
given agent.
|
Vector<ChatMessage> |
getHistory(URLDescriptor cd)
Retrieves the message history for the given cooperation domain.
|
Status |
informAgent_GUIOperationRequest(URLDescriptor receiverURL,
String content)
Deprecated.
|
void |
initializeAfterRegistered(boolean registered)
Overrides Agent.init().
|
protected TransientAgentInternalFrame |
makeDefaultInternalFrame(TransientAgent agent,
String title,
Container aFrame)
Create the default internal Frame (usually) with tabs for this agent type.
|
protected AgentUI |
makeDefaultTextInterface(String[] args)
Returns a default AgentUI as a window.
Subclasses should override ChatAgent.makeDefaultTextInterface() to change this behaviour in subclasses ChatAgent.makeDefaultTextInterface() may return null if no default interface can be built or is not desired. |
protected void |
nonMemberMessage(MLMessage message,
URLDescriptor sender) |
protected void |
pendingFinishRun()
Cleans up.
|
void |
putCooperationDomainHistory(URLDescriptor url,
Vector<ChatMessage> msg) |
PerformDescriptor |
release_join_cd(MLMessage msg)
This method is called when a cd.join reply message is received in response
to a previously sent cd.join request message.
|
PerformDescriptor |
release_withdraw_cd(MLMessage msg)
This method is called when a cd.withdraw reply message is received in
response to a previously sent cd.withdraw request message.
|
void |
removeCooperationDomainHistory(URLDescriptor url) |
void |
setObtainHistory(boolean obtainHistory)
Sets whether this
ChatAgent should obtain the history of any cooperation domain it joins. |
boolean |
willObtainHistory()
Returns whether this
ChatAgent will obtain the history of any
cooperation domain it joins. |
destroyDataObject, finalize, getAgentOptions, getBooleanProperty, getCASAFilename, getCreateDate, getDataObject, getDataObjectInputStream, getDataObjectOutputStream, getDoubleProperty, getFloatProperty, getIntegerProperty, getLongProperty, getOptions, getStringProperty, hasProperty, isPersistent, main, makeDefaultGUI, makeOptions, putDataObject, putDataObject, readPersistent, ready, realizeAgentBehaviourFromOptions, removeProperty, setBooleanProperty, setDoubleProperty, setFloatProperty, setIntegerProperty, setLongProperty, setOptions, setPersistent, setStringProperty, updateOptions, writePersistent
abclEval, abclEval, abclEval, accept_deleteCD, accept_exit, accept_forward_message, accept_LAC_closing, accept_new_MenuItem, accept_update, acceptDefault, addConversation, addJoinedCooperationDomain, addMembers, addSubscribeEvents, assembleDefault, assert_, assert_, authorizedByProxy, authorizeMessage, chooseSC, concludeDefault, consider_execute, consider_invite_to_cd, consider_new_MenuItem, consider_ping, consider_query_if, consider_query_ref, considerDefault, createCasaLispOperators, dispatchMsgHandlerMethod, doAddObserver, doAdvertise, doCDGetHistory_sync, doCDGetMembers, doCDPutData, doCDSubscribeMembership, doFindInstances_sync, doGetCooperationDomains, doGetOnology, doInviteToCD, doJoinCD, doPing_sync, doPing, doRegisterAgentInstance, doRegisterAgentInstance, doResolveURL, doSearchYP, doUnadvertise, doUnregisterAgentInstance, doUnregisterAgentType, doWithdrawCD, evaluateDefault, evesdrop, executeCommand, findFileResourcePath, findFileResourcePath, getAgentForThread, getAlwaysApplyPolicies, getBanner, getCachedKnowledgeBase, getChosenCommitment, getCommitmentProcessor, getConversation, getConversations, getConversationsReport, getDefaultBanner, getDefFileSystemLocations, getEventForThread, getField, getInstancesFound, getJoinedCooperationDomain, getJoinedCooperationDomains, getKnowledgeBase, getLACURL, getLastResortPolicies, getMembers, getMsgForThread, getObjectsForThread, getOntology, getOntologyEngine, getOntologyFileSuffix, getPolicies, getPrimaryUI, getProxy, getSCStore, getSerializedOntology, getStrategy, getStrategyGUI, getSubscribeEvents, getSubscribeEvents, getTermsFromContent, getUI, getUIForThread, getUIs, getUnfulfilledSocialCommitments, getUnfulfilledSocialCommitments, handleErrorReplies, handleEvent, handleLACClosing, hasActiveCommitments, hasConversation, hasStrategyGUI, initializePolicies, initializeThread, initJADE, initUI, isEventQueueReady, isRegistered, isRegisteredWithLAC, isStoppable, isTrusted, isTrusted, isUsingProxy, kb_get_value, makeDefaultInterface, monitorDefault, notifySendingMessage, optionsToString, parseJADENode, pendingFinishRun_unregisterAgentInstance, pendingFinishRun_withdrawFromAllCDs, perform_execute, perform_FIPAStyle, perform_get_name, perform_get_ontology, perform_invite_to_cd, perform_method_call, perform_query_if, perform_query_if, perform_query_ref, perform_query_ref, performDefault, processCommitment, processCommitments, processObserverNotification, putExtendedOntology, putPolicy, putPolicyAlwaysApply, putPolicyLastResort, putReplacementOntology, putUI, query_ref, query_toString, query, queryIf, queryRef_toIntegerList, queryRef_toString, queryRef_toStringList, queryRef_toTermList, queryRef, queryRef, queryRefAIDs, queryRefURLs, querywithFilter, recursiveParent, recursivePermutations, release_execute, release_FIPAStyle, release_get_agents_registered, release_get_agents_running, release_get_members, release_get_ontology, release_ping, release_query_if, release_query_ref, release_resolve_url, release_unregister_agentType, release_unregister_instance, releaseDefault, removeConversation, removeCooperationDomains, removeJoinedCooperationDomain, removeSubscribeEvents, requestInstances, resolveConnectException, retrieveReturnedData, saveReturnedData, searchOntology, searchOntology1, setBanner, setCommitmentProcessor, setField, setInstancesFound, setOntology, shouldDoExecuteRequest, template_handleNewOntologyInfo, update, updateConversationProtocolType, verifyCD, verifyDefault, verifyMessage
addObserver, addObserver, addObserver, addObserver, addTraceTags, addTransformation, bump, clearAllTraceTags, closePort, compareTo, countObservers, defer, defer, deleteObserver, deleteObserver, deleteObservers, dequeueEvent, equals, eventBufferLoopBody, eventBufferLoopPeriodic, eventQueuePeek, existed, exit, finishRun, fixupMessage, getAgent, getAgentName, getEventQueue, getInitParams, getNewMessage, getNewMessage, getPort, getSocketServer, getTrace, getTraceTags, getTransformationFor, getUniqueRequestID, getURL, getUseAckProtocol, getUsePriority, hasChanged, hasOpenPort, in, initializeConstructor, initializeURL, isA, isA, isA, isA, isAAct, isAAct, isAgentThread, isAPerformative, isAPerformative, isExiting, isInitialized, isLoggingTag, isObserveMessages, isPaused, isThisMyAddress, isTracing, loadClass, makeSubthread, makeSubthread, makeTraceParam, notifyObservers, notifyObservers, notifyObserversWithNoArg, notifyObserversWithTop, out, println, println, println, println, println, queueEvent, queueEventIf, removeTraceTags, resetRuntimeOptionsFromCommandLine, resetSecurityPackage, resetTraceOptions, revTransform, revTransform, run, sendMessage, sendMessage, sendMessageAndWait, sendQueryAndWait, sendRequestAndWait, sendRequestAndWait, setAllTraceTags, setObserveMessages, setPause, setTraceTags, setTracing, setURL, setUseAckProtocol, setUsePriority, startSocketServer, startTraceMonitor, step, transform, transform, unhandledMessage
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
getClass, hashCode, notify, notifyAll, wait, wait, wait
destroyDataObject, getBooleanProperty, getCASAFilename, getDataObject, getDataObjectInputStream, getDataObjectOutputStream, getDoubleProperty, getFloatProperty, getIntegerProperty, getLongProperty, getStringProperty, hasProperty, isPersistent, putDataObject, putDataObject, ready, removeProperty, setBooleanProperty, setDoubleProperty, setFloatProperty, setIntegerProperty, setLongProperty, setPersistent, setStringProperty
doAdvertise, doCDGetHistory_sync, doCDGetMembers, doCDPutData, doFindInstances_sync, doGetCooperationDomains, doGetOnology, doInviteToCD, doJoinCD, doPing_sync, doPing, doRegisterAgentInstance, doRegisterAgentInstance, doSearchYP, doUnadvertise, doUnregisterAgentInstance, doUnregisterAgentType, doWithdrawCD, executeCommand, getInstancesFound, getJoinedCooperationDomains, getLACURL, getMembers, getOntology, getOptions, getSerializedOntology, getStrategyGUI, hasStrategyGUI, isAAct, isInitialized, isRegistered, makeDefaultInterface, putExtendedOntology, putReplacementOntology, putUI, release_get_ontology, removeCooperationDomains, requestInstances, setOptions, updateOptions
addObserver, addObserver, closePort, deleteObserver, deleteObserver, exit, getAgentName, getName, getNewMessage, getPort, getStrategy, getTrace, getUniqueRequestID, getURL, getUseAckProtocol, hasOpenPort, isA, isAPerformative, isExiting, isLoggingTag, isStoppable, isTracing, println, println, println, realizeAgentBehaviourFromOptions, sendMessage, setTracing, setUseAckProtocol, startTraceMonitor
addObserver, addObserver, countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers, notifyObserversWithNoArg, notifyObserversWithTop
abclEval, abclEval, abclEval, addTransformation, bump, chooseSC, defer, dequeueEvent, dispatchMsgHandlerMethod, evesdrop, getKnowledgeBase, getName, getSCStore, getSubscribeEvents, getTransformationFor, getUniqueRequestID, getURL, getUseAckProtocol, isA, isA, isA, isA, isAPerformative, isAPerformative, isLoggingTag, notifyObservers, println, println, println, queueEvent, queueEventIf, revTransform, revTransform, sendMessage, transform, transform
private Hashtable<URLDescriptor,Vector<ChatMessage>> cooperationDomainHistories
Hashtable
linking the URLDescriptor
of a
cooperation domain to a Vector
of the message history
(ChatMessage
s) of that cooperation domain.ChatMessage
protected URLDescriptor currentCD
private boolean obtainHistory
private boolean setObtainHistory
public ChatAgent(ParamsMap params, AgentUI ui) throws Exception
ChatAgent
on the given port, with the given
name, registered with the LAC on the given port. The value of
obtainHistory
determines whether this agent will retrieve the
history of the cooperation domains it joins.port
- The port number to be used for communication with other
agents. See AbstractProcess.name
- The name of this Agent.obtainHistory
- Determines whether this agent will retrieve the
history of whatever cooperation domains it joins.lacPort
- The port number of the LAC that the agent should register
with.persistent
- Determines whether this agent is persistent or not.IPSocketException
- If an Agent attempts to bind to an IPSocket
(port) that doesn't exist or is in use.Exception
public void putCooperationDomainHistory(URLDescriptor url, Vector<ChatMessage> msg)
public void removeCooperationDomainHistory(URLDescriptor url)
public boolean canObtainHistory()
protected AgentUI makeDefaultTextInterface(String[] args)
makeDefaultTextInterface
in class TransientAgent
args
- The command line argumentspublic void setObtainHistory(boolean obtainHistory)
ChatAgent
should obtain the history of any cooperation domain it joins.setObtainHistory
in interface ChatAgentInterface
persistent
- Whether this Agent
's data should be persistent between instances.public boolean willObtainHistory()
ChatAgent
will obtain the history of any
cooperation domain it joins.willObtainHistory
in interface ChatAgentInterface
true
if this ChatAgent
will obtain the
history of any cooperation domain it joins; false
otherwise.public Vector<ChatMessage> getHistory(URLDescriptor cd)
getHistory
in interface ChatAgentInterface
cd
- The cooperation domain for which we are retrieving the history.Vector
of ChatMessage
s that have been
received from the given cooperation domain.public PerformDescriptor accept_chat_message(MLMessage message)
message
- The incoming message to be handled.Status
of 0, indicating that the message was
handled.public void chatMessage(URLDescriptor cd, MLMessage message)
chatMessage
in interface ChatAgentInterface
cd
- The cooperation domain that the message was sent through.message
- The chat message that was received.public Status doSendChatMessage(URLDescriptor cd, URLDescriptor to, boolean whisper, String message)
doSendChatMessage
in interface ChatAgentInterface
cd
- The cooperation domain that will forward the message.to
- The agent that will receive the message.whisper
- Constructs a whisper message if true
;
constructs a directed message if false
.message
- The message to send to the given agent.Status
of the message sending operation, 0 for
success; negative otherwise.Exception
- If an exception is thrown while sending the message.public Status doSendChatMessage(URLDescriptor cd, List<URLDescriptor> to, boolean whisper, String message)
doSendChatMessage
in interface ChatAgentInterface
cd
- The cooperation domain that will forward the message.to
- A Vector
containing the URLDescriptor
s
of the agents that will receive the message.whisper
- Constructs a whisper message if true
;
constructs a directed message if false
.message
- The message to send to the given agents.Status
of the message sending operation, 0 for
success; negative otherwise.public Status doSendChatMessage(URLDescriptor cd, String message)
doSendChatMessage
in interface ChatAgentInterface
cd
- The cooperation domain that will forward the message.message
- The message to send to the given agent.Status
of the message sending operation, 0 for
success; negative otherwise.Exception
- If an exception is thrown while sending the message.public PerformDescriptor release_withdraw_cd(MLMessage msg)
release_withdraw_cd
in class TransientAgent
msg
- The incoming message to be handled.Status
returned by the superclass function.public PerformDescriptor release_join_cd(MLMessage msg)
release_join_cd
in class TransientAgent
msg
- The incoming message to be handled.Status
returned by the superclass function.public void initializeAfterRegistered(boolean registered)
initializeAfterRegistered
in class Agent
registered
- Will be set to true if the agent has sucessfully registered with
the LAC; false otherwiseTransientAgent.initializeAfterRegistered(boolean)
protected void pendingFinishRun()
pendingFinishRun
in class Agent
AbstractProcess.pendingFinishRun()
protected TransientAgentInternalFrame makeDefaultInternalFrame(TransientAgent agent, String title, Container aFrame)
makeDefaultInternalFrame
in class Agent
agent
- the owner agenttitle
- the title of the windowaFrame
- the owner frame in which this window is to be embedded@Deprecated public Status informAgent_GUIOperationRequest(URLDescriptor receiverURL, String content)
receiverURL
- content
- protected PerformDescriptor accept_time(MLMessage message)
protected void nonMemberMessage(MLMessage message, URLDescriptor sender)