Package jade.core.behaviours
Class TickerBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.SimpleBehaviour
-
- jade.core.behaviours.TickerBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
public abstract class TickerBehaviour extends SimpleBehaviour
This abstract class implements aBehaviourthat periodically executes a user-defined piece of code. The user is expected to extend this class re-defining the methodonTick()and including the piece of code that must be periodically executed into it.- Author:
- Giovanni Caire - TILAB
- 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 TickerBehaviour(Agent a, long period)Construct aTickerBehaviourthat call itsonTick()method everyperiodms.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaction()Runs the behaviour.booleandone()Check if this behaviour is done.protected longgetPeriod()intgetTickCount()Retrieve how many ticks were done (i.e.voidonStart()This method is just an empty placeholders for subclasses.protected abstract voidonTick()This method is invoked periodically with the period defined in the constructor.voidreset()This method must be called to reset the behaviour and starts againvoidreset(long period)This method must be called to reset the behaviour and starts againvoidsetFixedPeriod(boolean fixedPeriod)Turn on/off the "fixed period" mode.voidstop()Make thisTickerBehaviourterminate.-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, handleBlockEvent, handleRestartEvent, isRunnable, onEnd, restart, root, setAgent, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Constructor Detail
-
TickerBehaviour
public TickerBehaviour(Agent a, long period)
Construct aTickerBehaviourthat call itsonTick()method everyperiodms.- Parameters:
a- is the pointer to the agentperiod- the tick period in ms
-
-
Method Detail
-
onStart
public void onStart()
Description copied from class:BehaviourThis method is just an empty placeholders for subclasses. It is executed just once before starting behaviour execution. Therefore, it acts as a prolog to the task represented by thisBehaviour.
-
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
-
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.
-
onTick
protected abstract void onTick()
This method is invoked periodically with the period defined in the constructor. Subclasses are expected to define this method specifying the action that must be performed at every tick.
-
setFixedPeriod
public void setFixedPeriod(boolean fixedPeriod)
Turn on/off the "fixed period" mode. Given a period P, when fixed period mode is off (default), this behaviour will wait for P milliseconds from the end of the n-th execution of the onTick() method to the beginning of the n+1-th execution. When fixed period is on, this behaviour will execute the onTick() method exactly every P milliseconds.- Parameters:
fixedPeriod- A boolean value indicating whether the fixed period mode must be turned on or off.
-
reset
public void reset(long period)
This method must be called to reset the behaviour and starts again- Parameters:
period- the new tick time
-
reset
public void reset()
This method must be called to reset the behaviour and starts again- Overrides:
resetin classSimpleBehaviour- Parameters:
timeout- indicates in how many milliseconds from now the behaviour must be waken up again.
-
stop
public void stop()
Make thisTickerBehaviourterminate. Calling stop() has the same effect as removing this TickerBehaviour, but is Thread safe
-
getTickCount
public final int getTickCount()
Retrieve how many ticks were done (i.e. how many times this behaviour was executed) since the last reset.- Returns:
- The number of ticks since the last reset
-
getPeriod
protected long getPeriod()
-
-