public abstract class TickerBehaviour extends SimpleBehaviour
Behaviour
that
periodically executes a user-defined piece of code.
The user is expected to extend this class re-defining the method
onTick()
and including the piece of code that
must be periodically executed into it.Constructor and Description |
---|
TickerBehaviour(Agent a,
long period)
Construct a
TickerBehaviour that call its
onTick() method every period ms. |
Modifier and Type | Method and Description |
---|---|
void |
action()
Runs the behaviour.
|
boolean |
done()
Check if this behaviour is done.
|
protected long |
getPeriod() |
int |
getTickCount()
Retrieve how many ticks were done (i.e. how many times this
behaviour was executed) since the last reset.
|
void |
onStart()
This method is just an empty placeholders for subclasses.
|
protected abstract void |
onTick()
This method is invoked periodically with the period defined in the
constructor.
|
void |
reset()
This method must be called to reset the behaviour and starts again
|
void |
reset(long period)
This method must be called to reset the behaviour and starts again
|
void |
setFixedPeriod(boolean fixedPeriod)
Turn on/off the "fixed period" mode.
|
void |
stop()
Make this
TickerBehaviour terminate. |
block, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onEnd, restart, root, setAgent, setBehaviourName, setDataStore
public TickerBehaviour(Agent a, long period)
TickerBehaviour
that call its
onTick()
method every period
ms.a
- is the pointer to the agentperiod
- the tick period in mspublic void onStart()
Behaviour
Behaviour
.public final void action()
Behaviour
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.action
in class Behaviour
CompositeBehaviour
public final boolean done()
Behaviour
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.protected abstract void onTick()
public void setFixedPeriod(boolean fixedPeriod)
fixedPeriod
- A boolean value indicating whether the fixed period mode must be turned on or off.public void reset(long period)
period
- the new tick timepublic void reset()
reset
in class SimpleBehaviour
timeout
- indicates in how many milliseconds from now the behaviour
must be waken up again.public void stop()
TickerBehaviour
terminate.
Calling stop() has the same effect as removing this TickerBehaviour, but is Thread safepublic final int getTickCount()
protected long getPeriod()