jade.core.behaviours
Class TickerBehaviour

java.lang.Object
  |
  +--jade.core.behaviours.Behaviour
        |
        +--jade.core.behaviours.SimpleBehaviour
              |
              +--jade.core.behaviours.TickerBehaviour
All Implemented Interfaces:
java.io.Serializable, Serializable

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

Field Summary
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, parent
 
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()
          Retrieve how many ticks were done (i.e.
 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
block, block, getBehaviourName, getDataStore, 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
 

Constructor Detail

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 agent
period - the tick period in ms
Method Detail

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 final void action()
Description copied from class: Behaviour
Runs the behaviour. This abstract method must be implemented by Behavioursubclasses 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.

Specified by:
action in class Behaviour
See Also:
CompositeBehaviour

done

public final 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.

Specified by:
done in 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

stop

public void stop()
This method makes this TickerBehaviour terminate


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


JADE