Package jade.core.behaviours
Class WakerBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.SimpleBehaviour
-
- jade.core.behaviours.WakerBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
public abstract class WakerBehaviour extends SimpleBehaviour
This abstract class implements a OneShot task that must be executed only one just after a given timeout is elapsed.The task is simply the call to the method
handleElapsedTimeout()that must be implemented by all subclasses. Notice that the best practice in JADE is when this method just adds a behaviour to the agent class.All subclasses have available the protected variable
myAgentthat points to the agent class.The programmer must use this abstract class in this simple way:
- implements a subclass that extends WakerBehaviour. This subclass
must implement the method
handleElapsedTimeout. - add the subclass to the list of behaviour of this agent by using
addBehaviour()method. - the method
handleElapsedTimeoutmust implement the task that will be executed after the timeout is elapsed.
- Version:
- $Date$ $Revision$
- Author:
- Fabio Bellifemine - CSELT S.p.A.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
-
-
Field Summary
-
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
-
-
Constructor Summary
Constructors Constructor Description WakerBehaviour(Agent a, long timeout)This method constructs the behaviour.WakerBehaviour(Agent a, Date wakeupDate)This method constructs the behaviour.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaction()Runs the behaviour.booleandone()Check if this behaviour is done.longgetWakeupTime()protected voidhandleElapsedTimeout()Deprecated.Use onWake() insteadprotected voidonWake()This method is invoked when the deadline defined in the constructor is reached (or when the timeout specified in the constructor expires).voidreset()This method must be called to reset the behaviour and starts againvoidreset(long timeout)This method must be called to reset the behaviour and starts againvoidreset(Date wakeupDate)This method must be called to reset the behaviour and starts againvoidstop()Make this WakerBehaviour terminate without calling the onWake() method.-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, handleBlockEvent, handleRestartEvent, isRunnable, onEnd, onStart, restart, root, setAgent, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Constructor Detail
-
WakerBehaviour
public WakerBehaviour(Agent a, Date wakeupDate)
This method constructs the behaviour.- Parameters:
a- is the pointer to the agentwakeupDate- is the date when the task must be executed
-
WakerBehaviour
public WakerBehaviour(Agent a, long timeout)
This method constructs the behaviour.- Parameters:
a- is the pointer to the agenttimeout- indicates the number of milliseconds after which the task must be executed
-
-
Method Detail
-
action
public final void action()
Description copied from class:BehaviourRuns the behaviour. This abstract method must be implemented byBehavioursubclasses to perform ordinary behaviour duty. An agent schedules its behaviours calling theiraction()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.- Specified by:
actionin classBehaviour- See Also:
CompositeBehaviour
-
onWake
protected void onWake()
This method is invoked when the deadline defined in the constructor is reached (or when the timeout specified in the constructor expires). Subclasses are expected to define this method specifying the action that must be performed at that time.
-
handleElapsedTimeout
protected void handleElapsedTimeout()
Deprecated.Use onWake() instead
-
reset
public void reset(Date wakeupDate)
This method must be called to reset the behaviour and starts again- Parameters:
wakeupDate- is the new time when the task must be executed again
-
reset
public void reset(long timeout)
This method must be called to reset the behaviour and starts again- Parameters:
timeout- indicates in how many milliseconds from now the behaviour must be waken up again.
-
reset
public void reset()
This method must be called to reset the behaviour and starts again- Overrides:
resetin classSimpleBehaviour
-
stop
public void stop()
Make this WakerBehaviour terminate without calling the onWake() method. Calling stop() has the same effect as removing this WakerBehaviour, but is Thread safe
-
done
public final boolean done()
Description copied from class:BehaviourCheck if this behaviour is done. The agent scheduler calls this method to see whether aBehaviourstill 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.
-
getWakeupTime
public final long getWakeupTime()
-
-