|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | 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.
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 |
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 |
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. |
AID |
getAID()
Method to query the private Agent ID. |
AID |
getAMS()
Get the Agent ID for the platform AMS. |
protected java.lang.Object[] |
getArguments()
Get the array of arguments passed to this agent. |
AgentContainer |
getContainerController()
Return a controller for this agents container. |
ContentManager |
getContentManager()
Retrieves the agent's content manager |
int |
getCurQueueSize()
This method retrieves the current lenght of the message queue of this agent. |
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). |
java.lang.Object |
getO2AObject()
This method picks an object (if present) from the internal object-to-agent communication queue. |
java.lang.String |
getProperty(java.lang.String key,
java.lang.String aDefault)
Retrieve a configuration property set in the Profile
of the local container (first) or as a System property. |
int |
getQueueSize()
Reads message queue size. |
Location |
here()
Method to retrieve the location this agent is currently at. |
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. |
void |
putO2AObject(java.lang.Object o,
boolean blocking)
This method should not be used by application code. |
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 |
removeBehaviour(Behaviour b)
This method removes a given behaviour from the agent. |
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 |
send(ACLMessage msg)
Send an ACL message to another agent. |
void |
setEnabledO2ACommunication(boolean enabled,
int queueSize)
This method declares this agent attitude towards object-to-agent communication, that is, whether the agent accepts to communicate with other non-JADE components living within the same JVM. |
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 |
Methods inherited from interface java.lang.Runnable |
run |
Constructor Detail |
public Agent()
Method Detail |
public final AID getAMS()
AID
object, that can be used to contact
the AMS of this platform.public final AID getDefaultDF()
AID
object, that can be used to contact
the default DF of this platform.public final AgentContainer getContainerController()
protected java.lang.Object[] getArguments()
Take care that the arguments are transient and they do not migrate with the agent neither are cloned with the agent!
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 Location here()
Location
object, describing the location
where this agent is currently running.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. When the number of
buffered
messages exceeds this value, older messages are discarded
according to a FIFO replacement policy.
java.lang.IllegalArgumentException
- If newSize
is negative.getQueueSize()
public int getCurQueueSize()
public int getQueueSize()
setQueueSize(int newSize)
,
getCurQueueSize()
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.
java.io.IOException
- Thrown if some I/O error occurs during
writing.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.
java.io.IOException
- Thrown if some I/O error occurs during
stream reading.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.
java.io.IOException
- Thrown if some I/O error occurs during
stream reading.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.
java.io.IOException
- Thrown if some I/O error occurs during
stream reading.
Note: This method is currently not implementedpublic void putO2AObject(java.lang.Object o, boolean blocking) throws java.lang.InterruptedException
jade.wrapper.Agent
instead.
java.lang.InterruptedException
Agent.putO2AObject(Object o, boolean blocking)
public java.lang.Object getO2AObject()
jade.core.Agent.setEnabledO2ACommunication()
method.
If the retrieved object was originally inserted by an external
component using a blocking call, that call will return during the
execution of this method.
null
if
the queue is empty.Agent.putO2AObject(Object o, boolean blocking)
,
setEnabledO2ACommunication(boolean enabled, int queueSize)
public void setEnabledO2ACommunication(boolean enabled, int queueSize)
enabled
- Tells whether Java objects inserted with
putO2AObject()
will be accepted.queueSize
- If the object-to-agent communication is enabled,
this parameter specifiies the maximum number of Java objects that
will be queued. If the passed value is 0, no maximum limit is set
up for the queue.Agent.putO2AObject(Object o, boolean blocking)
,
getO2AObject()
protected void setup()
Behaviour
object to the agent, in order for it to be
able to do anything.
addBehaviour(Behaviour b)
,
Behaviour
protected 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()
,
Behaviour
public void removeBehaviour(Behaviour b)
b
- The behaviour to remove.Behaviour
public 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.ACLMessage
public final ACLMessage receive()
null
if no message is
present.ACLMessage
public final ACLMessage receive(MessageTemplate pattern)
pattern
- A message template to match received messages
against.
null
if no such message is present.ACLMessage
,
MessageTemplate
public final ACLMessage blockingReceive()
receive()
,
ACLMessage
public 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)
pattern
- A message template to match received messages
against.
receive(MessageTemplate)
,
ACLMessage
,
MessageTemplate
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)
public ContentManager getContentManager()
public java.lang.String getProperty(java.lang.String key, java.lang.String aDefault)
Profile
of the local container (first) or as a System property.
key
- the key that maps to the property that has to be
retrieved.aDefault
- a default value to be returned if there is no mapping
for key
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |