|
|||||||||
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_IDLE
Represents the idle 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. |
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 |
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 |
doTimeOut(Timer t)
Restarts the behaviour associated with t. |
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. |
static byte[] |
extractPassword(java.lang.String ownership)
|
static java.lang.String |
extractUsername(java.lang.String ownership)
|
AID |
getAID()
Method to query the private Agent ID. |
AID |
getAMS()
Get the Agent ID for the platform AMS. |
protected java.lang.Object[] |
getArguments()
Return the array of arguments as they were set by the previous call of the method setArguments .
|
jade.security.Authority |
getAuthority()
|
jade.security.CertificateFolder |
getCertificateFolder()
|
AgentContainer |
getContainerController()
Return a controller for this agents container. |
ContentManager |
getContentManager()
Retrieves the agent's content manager |
int |
getCurQueueSize()
|
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. |
jade.security.AgentPrincipal |
getPrincipal()
|
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. |
int |
getState()
Read current agent state. |
Location |
here()
Method to retrieve the location this agent is currently at. |
void |
notifyChangeBehaviourState(Behaviour b,
java.lang.String from,
java.lang.String to)
|
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. |
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 |
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 |
setArguments(java.lang.Object[] args)
Called by AgentContainerImpl in order to pass arguments to a just created 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 |
setOwnership(java.lang.String ownership)
|
void |
setPrincipal(jade.security.CertificateFolder certs)
|
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 |
waitUntilStarted()
This method blocks until the agent has finished its start-up phase (i.e. until just before its setup() method is called. |
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_IDLE
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
protected Behaviour currentBehaviour
Behaviour
that is currently executing.Behaviour
protected 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 doTimeOut(Timer t)
TimerListener
interface.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 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()
public final void setArguments(java.lang.Object[] args)
protected java.lang.Object[] getArguments()
setArguments
.
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 jade.security.Authority getAuthority()
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.newSize
is negative.getQueueSize()
public int getCurQueueSize()
public int getQueueSize()
setQueueSize(int newSize)
,
getCurQueueSize()
public void setOwnership(java.lang.String ownership)
public static java.lang.String extractUsername(java.lang.String ownership)
public static byte[] extractPassword(java.lang.String ownership)
public void setPrincipal(jade.security.CertificateFolder certs)
public jade.security.AgentPrincipal getPrincipal()
public jade.security.CertificateFolder getCertificateFolder()
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 void putO2AObject(java.lang.Object o, boolean blocking) throws java.lang.InterruptedException
jade.wrapper.Agent
instead.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()
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)
,
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()
ReceiverBehaviour
to wait for a
message within a behaviour without suspending all the others and
without wasting CPU time doing busy waiting.ACLMessage
,
ReceiverBehaviour
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)
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 void waitUntilStarted()
public void notifyChangeBehaviourState(Behaviour b, java.lang.String from, java.lang.String to)
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: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |