unsw.cse.mica.tools.timer
Class TimerAgent

java.lang.Object
  extended by unsw.cse.mica.agent.DefaultAgent2
      extended by unsw.cse.mica.tools.timer.TimerAgent
All Implemented Interfaces:
Agent, MessageHandler, ITimerHandler

public class TimerAgent
extends DefaultAgent2
implements ITimerHandler

TimerAgent is a wrapper around a Timer, allowing for both one-off and repeated events to be generated. Events are added using "timerRequest" mobs or cancelled using "timerCancel" mobs. Event name and type Timer events must be given a name via the eventName slot. This is used by the agent to track events in order to allow subsequent event cancellation. Furthermore, the name is given as a preferred name for the resulting mob event. A timerRequest may also contain an eventType slot. If present, this value specifies the type of Mob that will be generated. If it is not present, the timerEvent type is used. Specifying event timing Each mob should contain one of:

If neither of these is found, the agent assumes an implicit relativeTime of zero, resulting in an event that will fire immediately.

To specify a recurring event, the follow slots are used:

Event information When an event fires and a Mob is created, eventName and eventTime slots are always added. All the non-event-related slots from the original request mob are then copied across as well. Cancelling events Events are cancelled using timerCancel events. The only required slot is eventName, which contains the name of the even to be cancelled. More than one event may be cancelled simultaneously by placing more than one name in the slot.

Author:
jhw

Field Summary
 
Fields inherited from class unsw.cse.mica.agent.DefaultAgent2
PARAM_NAME
 
Constructor Summary
TimerAgent()
          Create a new TimerAgent
 
Method Summary
 void fire(TimerEvent event)
          Fire an event.
 void handleNewMob(Mob mob)
          Handle incomnig Mobs.
 void init(MicaProperties args)
          Initialise the TimerAgent, by connectnig to the blackboard, registering for timerRequest and timerCancel events, and starting the internal Timer.
 void terminate()
          Terminate the agent.
 
Methods inherited from class unsw.cse.mica.agent.DefaultAgent2
getTransport, handleDeletedMob, handleReplacedMob, handleTypeManagerChanged, isATypeOf, setTransport
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimerAgent

public TimerAgent()
Create a new TimerAgent

Method Detail

init

public void init(MicaProperties args)
          throws MicaException
Initialise the TimerAgent, by connectnig to the blackboard, registering for timerRequest and timerCancel events, and starting the internal Timer.

Specified by:
init in interface Agent
Overrides:
init in class DefaultAgent2
Parameters:
args - Additional arguments provided to the agent. If the agent is started from with the 'Runner' tool, the args array contains the values provided from within the runner's XML configuration file. Otherwise, the exact contents will depend on the calling method.
Throws:
MicaException

terminate

public void terminate()
Terminate the agent.

Specified by:
terminate in interface Agent
Overrides:
terminate in class DefaultAgent2

handleNewMob

public void handleNewMob(Mob mob)
Handle incomnig Mobs. timerRequest are converted into events and added to the internal timer, while cancellation names are extracted and passed to the internal Timer.

Specified by:
handleNewMob in interface MessageHandler
Overrides:
handleNewMob in class DefaultAgent2
Parameters:
mob - the mob that has been written to the blackboard

fire

public void fire(TimerEvent event)
Fire an event. This method converts the event into a Mob and writes the Mob to the blackboard.

Specified by:
fire in interface ITimerHandler