|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--jade.core.Agent
The Agent class is the common superclass for user
defined software agents. It provides methods to perform basic agent
tasks, such as:
ACLMessage objects,
both unicast and multicast with optional pattern matching.
Agent subclasses, adding specific behaviours as needed
and exploiting Agent class capabilities.
| Field Summary | |
static int |
AP_ACTIVE
Represents the active agent state. |
static int |
AP_DELETED
Represents the deleted agent state. |
static int |
AP_INITIATED
Represents the initiated agent state. |
static int |
AP_MAX
Out of band value for Agent Platform Life Cycle states. |
static int |
AP_MIN
Out of band value for Agent Platform Life Cycle states. |
static int |
AP_SUSPENDED
Represents the suspended agent state. |
static int |
AP_TRANSIT
Represents the transit agent state. |
static int |
AP_WAITING
Represents the waiting agent state. |
protected Behaviour |
currentBehaviour
The Behaviour that is currently executing. |
protected ACLMessage |
currentMessage
Last message received. |
static int |
D_ACTIVE
Represents the active agent state. |
static int |
D_MAX
Out of band value for Domain Life Cycle states. |
static int |
D_MIN
Out of band value for Domain Life Cycle states. |
static int |
D_RETIRED
Represents the retired agent state. |
static int |
D_SUSPENDED
Represents the suspended agent state. |
static int |
D_UNKNOWN
Represents the unknown agent state. |
static int |
MSG_QUEUE_SIZE
Default value for message queue size. |
| Constructor Summary | |
Agent()
Default constructor. |
|
| Method Summary | |
void |
addBehaviour(Behaviour b)
This method adds a new behaviour to the agent. |
protected void |
afterClone()
Actions to perform after cloning. |
protected void |
afterMove()
Actions to perform after moving. |
protected void |
beforeClone()
Actions to perform before cloning. |
protected void |
beforeMove()
Actions to perform before moving. |
ACLMessage |
blockingReceive()
Receives an ACL message from the agent message queue. |
ACLMessage |
blockingReceive(long millis)
Receives an ACL message from the agent message queue, waiting at most a specified amount of time. |
ACLMessage |
blockingReceive(MessageTemplate pattern)
Receives an ACL message matching a given message template. |
ACLMessage |
blockingReceive(MessageTemplate pattern,
long millis)
Receives an ACL message matching a given message template, waiting at most a specified time. |
void |
deregisterLanguage(java.lang.String languageName)
Removes a Content Language from the agent capabilities. |
void |
deregisterOntology(java.lang.String ontologyName)
Removes an Ontology from the agent capabilities. |
void |
doActivate()
Make a state transition from suspended to active or waiting (whichever state the agent was in when doSuspend() was called) within Agent
Platform Life Cycle. |
void |
doClone(Location destination,
java.lang.String newName)
Make a state transition from active to copy within Agent Platform Life Cycle. |
void |
doDelete()
Make a state transition from active, suspended or waiting to deleted state within Agent Platform Life Cycle, thereby destroying the agent. |
void |
doMove(Location destination)
Make a state transition from active to transit within Agent Platform Life Cycle. |
void |
doStart(java.lang.String name)
Make a state transition from initiated to active within Agent Platform Life Cycle. |
void |
doSuspend()
Make a state transition from active or waiting to suspended within Agent Platform Life Cycle; the original agent state is saved and will be restored by a doActivate() call. |
void |
doWait()
Make a state transition from active to waiting within Agent Platform Life Cycle. |
void |
doWait(long millis)
Make a state transition from active to waiting within Agent Platform Life Cycle. |
void |
doWake()
Make a state transition from waiting to active within Agent Platform Life Cycle. |
java.util.List |
extractContent(ACLMessage msg)
Builds a Java object out of an ACL message. |
void |
fillContent(ACLMessage msg,
java.util.List content)
Fills the :content slot of an ACL message with the string
representation of a t-uple of user defined ontological objects. |
AID |
getAID()
Method to query the private Agent ID. |
static AID |
getAMS()
Get the Agent ID for the platform AMS. |
static AID |
getDefaultDF()
Get the Agent ID for the platform default DF. |
java.lang.String |
getHap()
Method to query the agent home address. |
java.lang.String |
getLocalName()
Method to query the agent local name. |
java.lang.String |
getName()
Method to query the agent complete name (GUID). |
int |
getQueueSize()
Reads message queue size. |
int |
getState()
Read current agent state. |
Codec |
lookupLanguage(java.lang.String languageName)
Looks a content language up into the supported languages table. |
Ontology |
lookupOntology(java.lang.String ontologyName)
Looks an ontology up into the supported ontologies table. |
void |
notifyRestarted(Behaviour b)
Notifies this agent that one of its behaviours has been restarted for some reason. |
void |
postMessage(ACLMessage msg)
Put a received message into the agent message queue. |
void |
putBack(ACLMessage msg)
Puts a received ACL message back into the message queue. |
static void |
read(java.io.InputStream s)
Read a previously saved agent from an input stream and restarts it under its former name. |
static void |
read(java.io.InputStream s,
java.lang.String agentName)
Read a previously saved agent from an input stream and restarts it under a different name. |
ACLMessage |
receive()
Receives an ACL message from the agent message queue. |
ACLMessage |
receive(MessageTemplate pattern)
Receives an ACL message matching a given template. |
void |
registerLanguage(java.lang.String languageName,
Codec translator)
Adds a Content Language codec to the agent capabilities. |
void |
registerOntology(java.lang.String ontologyName,
Ontology o)
Adds an Ontology to the agent capabilities. |
void |
removeBehaviour(Behaviour b)
This method removes a given behaviour from the agent. |
void |
restartLater(Behaviour b,
long millis)
Schedules a restart for a behaviour, after a certain amount of time has passed. |
void |
restore(java.io.InputStream s)
This method reads a previously saved agent, replacing the current state of this agent with the one previously saved. |
void |
run()
This method is the main body of every agent. |
void |
send(ACLMessage msg)
Send an ACL message to another agent. |
void |
setQueueSize(int newSize)
Set message queue size. |
protected void |
setup()
This protected method is an empty placeholder for application specific startup code. |
protected void |
takeDown()
This protected method is an empty placeholder for application specific cleanup code. |
void |
write(java.io.OutputStream s)
Write this agent to an output stream; this method can be used to record a snapshot of the agent state on a file or to send it through a network connection. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static final int AP_MIN
public static final int AP_INITIATED
public static final int AP_ACTIVE
public static final int AP_SUSPENDED
public static final int AP_WAITING
public static final int AP_DELETED
public static final int AP_TRANSIT
transit agent state.public static final int AP_MAX
public static final int D_MIN
public static final int D_ACTIVE
public static final int D_SUSPENDED
public static final int D_RETIRED
public static final int D_UNKNOWN
public static final int D_MAX
public static final int MSG_QUEUE_SIZE
setQueueSize(int newSize),
getQueueSize()protected Behaviour currentBehaviour
Behaviour that is currently executing.Behaviourprotected ACLMessage currentMessage
ACLMessage| Constructor Detail |
public Agent()
| Method Detail |
public void restartLater(Behaviour b,
long millis)
b - The behaviour to restart later.millis - The amount of time to wait before restarting
b.Behaviour.block(long millis)public void notifyRestarted(Behaviour b)
b, and it is unneeded by
application level code. To explicitly schedule behaviours, use
block() and restart() methods.b - The behaviour object which was restarted.Behaviour.restart()public static final AID getAMS()
AID object, that can be used to contact
the AMS of this platform.public static final AID getDefaultDF()
AID object, that can be used to contact
the default DF of this platform.public final java.lang.String getLocalName()
String containing the local agent name
(e.g. peter).public final java.lang.String getName()
String containing the complete agent name
(e.g. peter@fipa.org:50).public final AID getAID()
Agent ID object, containing the complete
agent GUID, addresses and resolvers.public final java.lang.String getHap()
String containing the agent home address
(e.g. iiop://fipa.org:50/acc).
public void registerLanguage(java.lang.String languageName,
Codec translator)
Codec
interface for the specific content language, and add it to its
languages table with this method.languageName - The symbolic name to use for the language.translator - A translator for the specific content language,
able to translate back and forth between text strings and Frame
objects.deregisterLanguage(String languageName),
Codecpublic Codec lookupLanguage(java.lang.String languageName)
languageName - The name of the desired content language.null if no translator was found.public void deregisterLanguage(java.lang.String languageName)
languageName - The name of the language to remove.registerLanguage(String languageName, Codec translator)
public void registerOntology(java.lang.String ontologyName,
Ontology o)
Ontology interface for the
specific ontology and add it to its ontologies table with this
method.ontologyName - The symbolic name to use for the ontologyo - An ontology object, that is able to convert back and
forth between Frame objects and application specific Java objects
representing concepts.deregisterOntology(String ontologyName),
Ontologypublic Ontology lookupOntology(java.lang.String ontologyName)
ontologyName - The name of the desired ontology.null if no such named
ontology was found.public void deregisterOntology(java.lang.String ontologyName)
ontologyName - The name of the ontology to remove.registerOntology(String ontologyName, Ontology o)
public java.util.List extractContent(ACLMessage msg)
throws FIPAException
:language slot to select a content language and the
:ontology slot to select an ontology. Then the
:content slot is interpreted according to the chosen
language and ontology, to build an object of a user defined class.msg - The ACL message from which a suitable Java object will
be built.registerLanguage(String languageName, Codec translator),
registerOntology(String ontologyName, Ontology o),
fillContent(ACLMessage msg, List content)
public void fillContent(ACLMessage msg,
java.util.List content)
throws FIPAException
:content slot of an ACL message with the string
representation of a t-uple of user defined ontological objects. Each
Java object in the given list
is first converted into a Frame object according to the
ontology present in the :ontology message slot, then the
Frame is translated into a String using the codec
for the content language indicated by the :language message
slot.
Notice that this method works properly only if in the Ontology each Java class has been registered to play just one role, otherwise ambiguity of role playing cannot be solved automatically.
msg - The ACL message whose content will be filled.content - A list of Java objects that will be converted into a string and
written inti the :content slot. This object must be an instance
of a class registered into the ontology named in the :ontology
message slot.:language or :ontology message slots contain an
unknown name, or if some problem occurs during the various translation steps.extractContent(ACLMessage msg),
registerLanguage(String languageName, Codec translator),
registerOntology(String ontologyName, Ontology o)
public void setQueueSize(int newSize)
throws java.lang.IllegalArgumentException
newSize - A non negative integer value to set message queue
size to. Passing 0 means unlimited message queue.newSize is negative.getQueueSize()public int getQueueSize()
setQueueSize(int newSize)public int getState()
public void doStart(java.lang.String name)
name - The local name of the agent.public void doMove(Location destination)
destination - The Location to migrate to.
public void doClone(Location destination,
java.lang.String newName)
destination - The Location where the copy agent will start.newName - The name that will be given to the copy agent.public void doSuspend()
doActivate() call. This method can be called from
the Agent Platform or from the agent iself and stops all agent
activities. Incoming messages for a suspended agent are buffered
by the Agent Platform and are delivered as soon as the agent
resumes. Calling doSuspend() on a suspended agent
has no effect.doActivate()public void doActivate()
doSuspend() was called) within Agent
Platform Life Cycle. This method is called from the Agent
Platform and resumes agent execution. Calling
doActivate() when the agent is not suspended has no
effect.doSuspend()public void doWait()
doWake() is called. Calling doWait() on
a suspended or waiting agent has no effect.doWake()public void doWait(long millis)
doWait() version.millis - The timeout value, in milliseconds.doWait()public void doWake()
doWake() when an agent is not waiting has no effect.doWait()public void doDelete()
doDelete() on an already deleted
agent has no effect.
public void write(java.io.OutputStream s)
throws java.io.IOException
s - The stream this agent will be sent to. The stream is
not closed on exit.read(InputStream s)
public static void read(java.io.InputStream s)
throws java.io.IOException
s - The stream the agent will be read from. The stream is
not closed on exit.write(OutputStream s)
public static void read(java.io.InputStream s,
java.lang.String agentName)
throws java.io.IOException
s - The stream the agent will be read from. The stream is
not closed on exit.agentName - The name of the new agent, copy of the saved
original one.write(OutputStream s)
public void restore(java.io.InputStream s)
throws java.io.IOException
s - The input stream the agent state will be read from.public final void run()
setup(),
takeDown()protected void setup()
Behaviour object to the agent, in order for it to be
able to do anything.addBehaviour(Behaviour b),
Behaviourprotected void takeDown()
protected void beforeMove()
protected void afterMove()
protected void beforeClone()
protected void afterClone()
public void addBehaviour(Behaviour b)
setup() to fire off some
initial behaviour, but can also be used to spawn new behaviours
dynamically.b - The new behaviour to add to the agent.setup(),
Behaviourpublic void removeBehaviour(Behaviour b)
b - The behaviour to remove.Behaviourpublic final void send(ACLMessage msg)
:receiver
message field (more than one agent can be specified as message
receiver).msg - An ACL message object containing the actual message to
send.ACLMessagepublic final ACLMessage receive()
null if no message is
present.ACLMessagepublic final ACLMessage receive(MessageTemplate pattern)
pattern - A message template to match received messages
against.null if no such message is present.ACLMessage,
MessageTemplatepublic final ACLMessage blockingReceive()
ReceiverBehaviour to wait for a
message within a behaviour without suspending all the others and
without wasting CPU time doing busy waiting.ACLMessage,
ReceiverBehaviourpublic final ACLMessage blockingReceive(long millis)
millis - The maximum amount of time to wait for the message.null if the specified
amount of time passes without any message reception.public final ACLMessage blockingReceive(MessageTemplate pattern)
ReceiverBehaviour to wait
for a specific kind of message within a behaviour without
suspending all the others and without wasting CPU time doing busy
waiting.pattern - A message template to match received messages
against.ACLMessage,
MessageTemplate,
ReceiverBehaviour
public final ACLMessage blockingReceive(MessageTemplate pattern,
long millis)
pattern - A message template to match received messages
against.millis - The amount of time to wait for the message, in
milliseconds.null if no suitable message was received within
millis milliseconds.blockingReceive()public final void putBack(ACLMessage msg)
receive() call.receive()public final void postMessage(ACLMessage msg)
msg - The ACL message to put in the queue.send(ACLMessage msg)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||