|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jade.core.behaviours.Behaviour
Abstract base class for JADE behaviours. Extending this class directly should only be needed for particular behaviours with special synchronization needs; this is because event based notification used for blocking and restarting behaviours is directly accessible at this level.
Inner Class Summary | |
protected class |
Behaviour.RunnableChangedEvent
Event class for notifying blocked and restarted behaviours. |
Field Summary | |
protected Agent |
myAgent
The agent this behaviour belongs to. |
protected Behaviour.RunnableChangedEvent |
myEvent
This event object will be re-used for every state change notification. |
protected static int |
NOTIFY_DOWN
A constant for parent-to-child notifications. |
protected static int |
NOTIFY_UP
A constant for child-to-parent notifications. |
protected CompositeBehaviour |
parent
Back pointer to the enclosing Behaviour (if present). |
static java.lang.String |
STATE_BLOCKED
A constant identifying the blocked state. |
static java.lang.String |
STATE_READY
A constant identifying the runnable state. |
static java.lang.String |
STATE_RUNNING
A constant identifying the running state. |
Constructor Summary | |
Behaviour()
Default constructor. |
|
Behaviour(Agent a)
Constructor with owner agent. |
Method Summary | |
abstract void |
action()
Runs the behaviour. |
void |
actionWrapper()
This method is called internally by the JADE framework and should not be called by the user. |
void |
block()
Blocks this behaviour. |
void |
block(long millis)
Blocks this behaviour for a specified amount of time. |
abstract boolean |
done()
Check if this behaviour is done. |
java.lang.String |
getBehaviourName()
|
DataStore |
getDataStore()
Return the private data store of this Behaviour .
|
protected void |
handle(Behaviour.RunnableChangedEvent rce)
Handler for block/restart events. |
boolean |
isRunnable()
Returns whether this Behaviour object is blocked or
not. |
int |
onEnd()
This method is just an empty placeholder for subclasses. |
void |
onStart()
This method is just an empty placeholders for subclasses. |
void |
reset()
Restores behaviour initial state. |
void |
restart()
Restarts a blocked behaviour. |
Behaviour |
root()
Returns the root for this Behaviour object. |
void |
setAgent(Agent a)
Associates this behaviour with the agent it belongs to. |
void |
setBehaviourName(java.lang.String name)
|
void |
setDataStore(DataStore ds)
Set the private data store of this Behaviour |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected static final int NOTIFY_UP
protected static final int NOTIFY_DOWN
public static final java.lang.String STATE_READY
public static final java.lang.String STATE_BLOCKED
public static final java.lang.String STATE_RUNNING
protected Agent myAgent
Behaviour
is the superclass
of all the other behaviour classes, this variable is always
available. Of course, remind to use the appropriate constructor,
i.e. the one that accepts an agent object as argument; otherwise,
this variable is set to null
.protected Behaviour.RunnableChangedEvent myEvent
protected CompositeBehaviour parent
CompositeBehaviour
Constructor Detail |
public Behaviour()
public Behaviour(Agent a)
a
- The agent owning this behaviour.Method Detail |
public final void setBehaviourName(java.lang.String name)
public final java.lang.String getBehaviourName()
public abstract void action()
Behaviour
subclasses to perform ordinary behaviour
duty. An agent schedules its behaviours calling their
action()
method; since all the behaviours belonging
to the same agent are scheduled cooperatively, this method
must not enter in an endless loop and should return as
soon as possible to preserve agent responsiveness. To split a
long and slow task into smaller section, recursive behaviour
aggregation may be used.CompositeBehaviour
public abstract boolean done()
Behaviour
still need to be
run or it has completed its task. Concrete behaviours must
implement this method to return their completion state. Finished
behaviours are removed from the scheduling queue, while others
are kept within to be run again when their turn comes again.true
if the behaviour has completely executed.public int onEnd()
Behaviour
.
onEnd
is called after the behaviour has been
removed from the pool of behaviours to be executed by an agent.
Therefore calling
reset()
is not sufficient to cyclically repeat the task
represented by this Behaviour
. In order to achieve that,
this Behaviour
must be added again to the agent
(using myAgent.addBehaviour(this)
). The same applies to
in the case of a Behaviour
that is a child of a
ParallelBehaviour
.public void onStart()
Behaviour
.public final void actionWrapper()
public void reset()
reset()
on a behaviour object is equivalent to
destroying it and recreating it back. The main purpose for this
method is to realize multistep cyclic behaviours without needing
expensive constructions an deletion of objects at each loop
iteration.
This method provides also to clear the dataStore.
Remind to call super.reset() from the sub-classes.protected void handle(Behaviour.RunnableChangedEvent rce)
rce
- The event to handlepublic Behaviour root()
Behaviour
object. That is,
the top-level behaviour this one is a part of. Agents apply
scheduling only to top-level behaviour objects, so they just call
restart()
on root behaviours.this
is returned.restart()
public boolean isRunnable()
Behaviour
object is blocked or
not.true
when this behaviour is not blocked,
false
when it is.public void block()
action()
method, behaviour
suspension occurs as soon as action()
returns.restart()
public void block(long millis)
millis
milliseconds has passed
since the call to block()
.
restart()
is called explicitly on
this behaviour object.
millis
- The amount of time to block, in
milliseconds. Notice: a value of 0 for
millis
is equivalent to a call to
block()
without arguments.block()
public void restart()
block()
public void setAgent(Agent a)
addBehaviour()
call takes care of the association
transparently.a
- The agent this behaviour belongs to.Agent.addBehaviour(Behaviour b)
public DataStore getDataStore()
Behaviour
.
If it was null, a new DataStore is created and returned.Behaviour
public void setDataStore(DataStore ds)
Behaviour
ds
- the DataStore
that this Behaviour
will use as its private data store
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |