net.ponder2
Class Timer

java.lang.Object
  extended by net.ponder2.Timer
All Implemented Interfaces:
ManagedObject

public class Timer
extends java.lang.Object
implements ManagedObject

Implements a multiple timer. Events may be fired off at regular intervals or after a single interval.
Time can be given in milliseconds as a simple number or as hh:mm:ss. e.g. 0:22 would be 22 seconds.
If the event is declared with a count attribute then the attribute will be set to the event number before each event is sent.

Version:
$Id:$
Author:
Kevin Twidle

Nested Class Summary
 class Timer.Ticker
           
 
Method Summary
protected  void cancel()
          stops and cancels all the timers.
protected  void cancel(int anIndex)
          stops and cancels the timer at anIndex.
protected  int repeat(P2Object source, java.lang.String time, P2Object event)
          sets up and starts a repetitive timer that send the event periodically.
protected  void start(int anIndex)
          starts the timer at anIndex
protected  void stop(int anIndex)
          stops the timer at anIndex
protected  int tick(P2Object source, java.lang.String time, P2Object event)
          sets up and starts a one off timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

tick

protected int tick(P2Object source,
                   java.lang.String time,
                   P2Object event)
            throws Ponder2ArgumentException
sets up and starts a one off timer. Sends the event after the specified time.

Parameters:
time - the time before the event is sent
event - the event to send
Returns:
the timer's index for later stopping or restarting
Throws:
Ponder2ArgumentException

repeat

protected int repeat(P2Object source,
                     java.lang.String time,
                     P2Object event)
              throws Ponder2ArgumentException
sets up and starts a repetitive timer that send the event periodically.

Parameters:
time - the time before the event is sent
event - the event to send
Returns:
the timer's index for later stopping or restarting
Throws:
Ponder2ArgumentException

start

protected void start(int anIndex)
starts the timer at anIndex

Parameters:
anIndex - the index of the timer to be started

stop

protected void stop(int anIndex)
stops the timer at anIndex

Parameters:
anIndex - the index of the timer to be stopped

cancel

protected void cancel()
stops and cancels all the timers. The indexes are invalid after this operation.


cancel

protected void cancel(int anIndex)
stops and cancels the timer at anIndex. anIndex cannot be used again.

Parameters:
anIndex -


Copyright © 2008 Imperial College. All Rights Reserved.