public class Agent extends TransientAgent implements AgentInterface
Agent
is an extension of TransientAgent
that adds the possibility
to store properties and data. These can be stored persistently or can be temporary for each
instance.
WARNING! You cannot do anything with the CASAFile data file (or the properties) within
the constructor. If you need to do this, override TransientAgent.initializeThread(ParamsMap, AgentUI)
and put such initialization in that method.
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.
TransientAgent
TransientAgent.Conversations, TransientAgent.NewAgentLispCommand
AbstractProcess.Subthread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
protected boolean |
agentConstructorComplete
Set to true when the constructor completes.
|
private CASAFile |
dataFile
Stores all of the data corresponding to the current
Agent . |
private String |
dataFileName
The fully qualified filename of the file that the agent stores persistent
date in.
|
private Tristate |
persistent
Determines whether this agent's data will be persistent:
true if this agent's data will be persistent between
instances; false otherwise. |
protected CASAFilePropertiesMap |
properties
Stores the properties for this agent.
|
cacheKB, CDInvitedTo, CDinvitee, conversationData, defaultOntologyClassName, DEFER_ACTION, DROP_ACTION, kBase, lisp, lispEnvironment, ListOfArgs, methodMap, ontologyEngine, ontologyEngineCreateMethod, ontologyEngineLoadMethod, policies, policiesAlwaysApply, policiesLastResort, primaryUI, proxy, UIs, usingProxy
eventQueue, exitWaitCounter, heartbeat, huntForPort, initParams, ontology, ontologyShared, options, securityFilter, trace, TRACE_MONITOR, TRACE_OFF, TRACE_ON, TRACE_TO_FILE, TRACE_UNDEFINED, transformations, uniqueThreadName, waitingForAgentToStart, waitingForEvent, waitingForSocketServerToStart
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
Agent(ParamsMap params,
AgentUI ui)
Standard constructor
|
Modifier and Type | Method and Description |
---|---|
private void |
createDirectories()
Creates all sub directories needed to write the
CASAFile
for this agent. |
boolean |
destroyDataObject(String dataObjectName)
Destroys the specified data object, deleting the corresponding node in
the
CASAFile . |
protected void |
finalize()
Overrides
Object.finalize() in order to perform a final
clean up to the resources used by an Agent . |
AgentOptions |
getAgentOptions() |
boolean |
getBooleanProperty(String name)
Retrieves the boolean property, returning it to the user.
|
String |
getCASAFilename()
Returns the filename of the
CASAFile that will be used by
this agent to store its properties and data either temporarily or
persistently. |
String |
getCreateDate() |
StatusString |
getDataObject(String dataObjectName)
Retreives a
StatusDataDescriptor for this agent from the
specified data object. |
InputStream |
getDataObjectInputStream(String dataObjectName)
Returns an
InputStream that can be used to read from the
specified data object. |
OutputStream |
getDataObjectOutputStream(String dataObjectName,
boolean append)
Returns an
OutputStream that can be used to write to the
specified data object. |
double |
getDoubleProperty(String name)
Retrieves the double precision floating point property, returning it to
the user.
|
float |
getFloatProperty(String name)
Retrieves the floating point property, returning it to the user.
|
int |
getIntegerProperty(String name)
Retrieves the integer property, returning it to the user.
|
long |
getLongProperty(String name)
Retrieves the long integer property, returning it to the user.
|
AgentOptions |
getOptions()
Returns a reference to this object's
ProcessOptions object. |
String |
getStringProperty(String name)
Retrieves the String property, returning it to the user.
|
boolean |
hasProperty(String propertyName)
Returns whether the specified property is contained in the properties.
|
void |
initializeAfterRegistered(boolean registered)
Called by handleReply_registerAgentInstance.
|
private void |
initializeFile()
This initializes both the
CASAFile that will be used to
store the data, and the properties object. |
boolean |
isPersistent()
Returns whether this agent's data will be persistent between instances.
|
static void |
main(String[] args) |
protected AgentUI |
makeDefaultGUI(String[] args)
Returns a default AgentUI as a window.
|
protected TransientAgentInternalFrame |
makeDefaultInternalFrame(TransientAgent agent,
String title,
Container aFrame)
Create the default internal Frame (usually) with tabs for this agent type.
|
protected ProcessOptions |
makeOptions()
Factory method to make a new options object.
|
protected void |
pendingFinishRun()
This is called when the agent is shutting down.
|
Status |
putDataObject(DataStorageDescriptor dsd)
Stores some data for this agent based on the specified
DataStorageDescriptor . |
Status |
putDataObject(String data,
String dataObjectName,
boolean append)
Stores a
DataDescriptor for this agent to the specified
data object. |
void |
readPersistent()
Uses the
properties object to read in all of this agent's attributes tagged with
the @CasaPersistent annotation from persistent store. |
boolean |
ready()
Determines if the agent has been fully initialized: registered with the
LAC and initialized its data file and properties.
|
void |
realizeAgentBehaviourFromOptions()
Refresh agent behaviour from the options object.
|
void |
removeProperty(String propertyName)
Removes the property from the properties.
|
void |
setBooleanProperty(String name,
boolean value)
Stores a boolean property.
|
void |
setDoubleProperty(String name,
double value)
Stores a double precision floating point property.
|
void |
setFloatProperty(String name,
float value)
Stores a floating point property.
|
void |
setIntegerProperty(String name,
int value)
Stores an integer property.
|
void |
setLongProperty(String name,
long value)
Stores a long integer property.
|
void |
setOptions(ProcessOptions options)
Sets this object's ProcessOptions object.
|
void |
setPersistent(boolean persistent)
Sets whether this
Agent 's data should be persistent
between instances. |
void |
setStringProperty(String name,
String value)
Stores a String property.
|
void |
updateOptions()
Save the options.
|
void |
writePersistent()
Uses the
properties object to write out all of this agent's attributes tagged with
the @CasaPersistent annotation to persistent store. |
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, makeDefaultTextInterface, 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_join_cd, release_ping, release_query_if, release_query_ref, release_resolve_url, release_unregister_agentType, release_unregister_instance, release_withdraw_cd, 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_primitive, 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
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, getSerializedOntology, getStrategyGUI, hasStrategyGUI, isAAct, isInitialized, isRegistered, makeDefaultInterface, putExtendedOntology, putReplacementOntology, putUI, release_get_ontology, removeCooperationDomains, requestInstances
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, 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 CASAFile dataFile
Agent
. If this agent is not persistent, this file will be deleted when the agent is shut down.private String dataFileName
protected CASAFilePropertiesMap properties
dataFile
.private Tristate persistent
true
if this agent's data will be persistent between
instances; false
otherwise. By default the value is
false
.protected boolean agentConstructorComplete
public static void main(String[] args)
public boolean ready()
ready
in interface AgentInterface
public void readPersistent()
properties
object to read in all of this agent's attributes tagged with
the @CasaPersistent
annotation from persistent store.public void initializeAfterRegistered(boolean registered)
TransientAgent.initializeAfterRegistered(boolean)
) after processing the persistent data.initializeAfterRegistered
in class TransientAgent
registered
- Will be set to true if the agent has sucessfully registered with
the LAC; false otherwiseTransientAgent.initializeAfterRegistered(boolean)
public void realizeAgentBehaviourFromOptions()
realizeAgentBehaviourFromOptions
in interface ProcessInterface
realizeAgentBehaviourFromOptions
in class TransientAgent
public String getCASAFilename() throws FileNotFoundException
CASAFile
that will be used by
this agent to store its properties and data either temporarily or
persistently.getCASAFilename
in interface AgentInterface
CASAFile
that will be used by
this agent to store its properties and data.FileNotFoundException
public String getCreateDate()
private void createDirectories() throws IOException
CASAFile
for this agent.IOException
- If one of the directories could not be created.private void initializeFile() throws IOException
CASAFile
that will be used to
store the data, and the properties object.IOException
public void setPersistent(boolean persistent)
Agent
's data should be persistent
between instances.setPersistent
in interface AgentInterface
persistent
- Whether this Agent
's data should be persistent
between instances.public AgentOptions getAgentOptions()
public boolean isPersistent()
isPersistent
in interface AgentInterface
true
if this agent's data will be persistent
between instances; false
otherwise.public boolean destroyDataObject(String dataObjectName) throws IOException
CASAFile
. A boolean value is returned as to whether
the data object existed in the first place.destroyDataObject
in interface AgentInterface
dataObjectName
- The name of the data object that we wish to destroy.true
if the data object existed and was
successfully destroyed; false
otherwise.IOException
- If there is a problem removing the node from the
CASAFile
, such as a non-existent file.public Status putDataObject(DataStorageDescriptor dsd)
DataStorageDescriptor
. The Status
is
returned indicating the success of the operation.putDataObject
in interface AgentInterface
dsd
- The DataStorageDescriptor
that specifies what
data is to be written as well as to which dataobject it should
be written.Status
object indicating the result of the
attempt.public Status putDataObject(String data, String dataObjectName, boolean append)
DataDescriptor
for this agent to the specified
data object. The Status
is returned indicating the success
of the operation.putDataObject
in interface AgentInterface
data
- The DataDescriptor
to be stored.dataObjectName
- The name of the data object that will be written to or written
over.append
- Sets whether the data object should be appended to, or
overwritten.Status
object indicating the result of the
attempt.public OutputStream getDataObjectOutputStream(String dataObjectName, boolean append) throws IOException
OutputStream
that can be used to write to the
specified data object.getDataObjectOutputStream
in interface AgentInterface
dataObjectName
- The name of the data object that the OutputStream
will write to.append
- Sets whether the data object will be appended to, or
overwritten by the OutputStream
.OutputStream
that can be used to write to the
specified data object.IOException
- If there is a problem creating the OutputStream
for the specified data object.public InputStream getDataObjectInputStream(String dataObjectName) throws IOException
InputStream
that can be used to read from the
specified data object.getDataObjectInputStream
in interface AgentInterface
dataObjectName
- The name of the data object that the InputStream
will read from.InputStream
that can be used to read from the
specified data object.IOException
- If there is a problem creating the InputStream
for the specified data object.public StatusString getDataObject(String dataObjectName)
StatusDataDescriptor
for this agent from the
specified data object. The StatusDataDescriptor
contains
the status of the attempt and the data of the specified data object.getDataObject
in interface AgentInterface
dataObjectName
- The name of the data object that will be read from.StatusDataDescriptor
containing the status of
the attempt and the data of the specified data object.public void setBooleanProperty(String name, boolean value)
setBooleanProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public boolean getBooleanProperty(String name) throws PropertyException
getBooleanProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not a boolean property.public void setStringProperty(String name, String value)
setStringProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public String getStringProperty(String name) throws PropertyException
getStringProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not a String property.public void setIntegerProperty(String name, int value)
setIntegerProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public int getIntegerProperty(String name) throws PropertyException
getIntegerProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not an integer property.public void setLongProperty(String name, long value)
setLongProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public long getLongProperty(String name) throws PropertyException
getLongProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not a long integer property.public void setFloatProperty(String name, float value)
setFloatProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public float getFloatProperty(String name) throws PropertyException
getFloatProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not a floating point property.public void setDoubleProperty(String name, double value)
setDoubleProperty
in interface AgentInterface
name
- The name of the property to store.value
- The value of the property that matches the name given.public double getDoubleProperty(String name) throws PropertyException
getDoubleProperty
in interface AgentInterface
name
- The name of the property to retrieve.PropertyException
- If the given property is not a double precision floating
point property.public boolean hasProperty(String propertyName)
hasProperty
in interface AgentInterface
propertyName
- The name of the property that we are checking for.true
if there exists a property with the specified
name; false
otherwise.public void removeProperty(String propertyName)
removeProperty
in interface AgentInterface
propertyName
- The name of the property to be removed.public void updateOptions()
updateOptions
in interface ProcessInterface
updateOptions
in interface TransientAgentInterface
updateOptions
in class AbstractProcess
protected void pendingFinishRun()
CASAFile
.pendingFinishRun
in class TransientAgent
AbstractProcess.pendingFinishRun()
protected void finalize() throws Throwable
Object.finalize()
in order to perform a final
clean up to the resources used by an Agent
. Called by the
garbage collector on an Agent's
object when garbage
collection determines that there are no more references to such object.finalize
in class AbstractProcess
Throwable
- May be thrown by super.finalize().protected ProcessOptions makeOptions()
AbstractProcess
makeOptions
in class AbstractProcess
public AgentOptions getOptions()
AbstractProcess
ProcessOptions
object.getOptions
in interface PolicyAgentInterface
getOptions
in interface ProcessInterface
getOptions
in interface TransientAgentInterface
getOptions
in class AbstractProcess
ProcessOptions
object.public void setOptions(ProcessOptions options)
AbstractProcess
setOptions
in interface ProcessInterface
setOptions
in interface TransientAgentInterface
setOptions
in class AbstractProcess
options
- a reference to a ProcessOptions object will become this agent's
options objectpublic void writePersistent()
properties
object to write out all of this agent's attributes tagged with
the @CasaPersistent
annotation to persistent store.protected AgentUI makeDefaultGUI(String[] args)
TransientAgent
makeDefaultGUI
in class TransientAgent
args
- The command line argumentsprotected TransientAgentInternalFrame makeDefaultInternalFrame(TransientAgent agent, String title, Container aFrame)
makeDefaultInternalFrame
in class TransientAgent
agent
- the owner agenttitle
- the title of the windowaFrame
- the owner frame in which this window is to be embedded