jade.core.behaviours
Class TickerBehaviour
java.lang.Object
|
+--jade.core.behaviours.Behaviour
|
+--jade.core.behaviours.SimpleBehaviour
|
+--jade.core.behaviours.TickerBehaviour
- public abstract class TickerBehaviour
- extends SimpleBehaviour
This abstract class implements a 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.
- Author:
- Giovanni Caire - TILAB
- See Also:
- Serialized Form
Constructor Summary |
TickerBehaviour(Agent a,
long period)
Construct a TickerBehaviour that call its
onTick() method every period ms. |
Method Summary |
void |
action()
Runs the behaviour. |
boolean |
done()
Check if this behaviour is done. |
int |
getTickCount()
|
void |
onStart()
This method is just an empty placeholders for subclasses. |
protected abstract void |
onTick()
Subclasses are expected to define this method specifying the action
that must be performed at every tick |
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 |
stop()
This method makes this TickerBehaviour terminate |
Methods inherited from class jade.core.behaviours.Behaviour |
actionWrapper,
block,
block,
getBehaviourName,
getDataStore,
handle,
isRunnable,
onEnd,
restart,
root,
setAgent,
setBehaviourName,
setDataStore |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
TickerBehaviour
public TickerBehaviour(Agent a,
long period)
- Construct a
TickerBehaviour
that call its
onTick()
method every period
ms.
- Parameters:
a
- is the pointer to the agentperiod
- the tick period in ms
onStart
public final void onStart()
- Description copied from class: Behaviour
- This 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 this
Behaviour
.
- Overrides:
- onStart in class Behaviour
action
public void action()
- Description copied from class: Behaviour
- Runs the behaviour. This abstract method must be implemented by
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.
- Overrides:
- action in class Behaviour
- Tags copied from class: Behaviour
- See Also:
CompositeBehaviour
done
public boolean done()
- Description copied from class: Behaviour
- Check if this behaviour is done. The agent scheduler calls this
method to see whether a
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.
- Overrides:
- done in class Behaviour
- Tags copied from class: Behaviour
- Returns:
true
if the behaviour has completely executed.
onTick
protected abstract void onTick()
- Subclasses are expected to define this method specifying the action
that must be performed at every tick
- Returns:
- when this method returns
true
the
TickerBehaviour
terminates
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:
- reset in class SimpleBehaviour
- Parameters:
timeout
- indicates in how many milliseconds from now the behaviour
must be waken up again.
stop
public void stop()
- This method makes this
TickerBehaviour
terminate
getTickCount
public int getTickCount()
- Returns:
- The number of ticks since the last reset