org.kaariboga.util
Class SimpleTimer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.kaariboga.util.SimpleTimer
All Implemented Interfaces:
java.lang.Runnable

public class SimpleTimer
extends java.lang.Thread

A simple timer. This timer calls onSimpleTimer() of a SimpleTimerListener in regular time intervals.

See Also:
SimpleTimerListener

Field Summary
protected  long interval
          interval to wait between notifications
protected  SimpleTimerListener listener
          The class, that is notified by this timer.
protected  boolean reset
          used to indicate if this timer has been reset
protected  boolean shouldLive
          used to control, if this thread should terminate
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
SimpleTimer(long interval, boolean startImmediately, SimpleTimerListener listener)
          Creates a new Timer that notifies it's listener once in every interval
 
Method Summary
 void reset()
          Resets this timer.
 void run()
          Just waits a specified time and notifies the listener.
 void terminate()
          Terminates this timer.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

interval

protected long interval
interval to wait between notifications

listener

protected SimpleTimerListener listener
The class, that is notified by this timer.

shouldLive

protected volatile boolean shouldLive
used to control, if this thread should terminate

reset

protected volatile boolean reset
used to indicate if this timer has been reset
Constructor Detail

SimpleTimer

public SimpleTimer(long interval,
                   boolean startImmediately,
                   SimpleTimerListener listener)
Creates a new Timer that notifies it's listener once in every interval
Parameters:
interval - Interval in milliseconds this timer notifies the listener
startImmeiately - Determines if the timer should start or wait for the first interval before calling onSimpleTimer.
agent - The agent, that is notified by this timer
Method Detail

run

public void run()
Just waits a specified time and notifies the listener.
Overrides:
run in class java.lang.Thread

reset

public void reset()
Resets this timer. If the timer has been reset, it starts again waiting the given time interval

terminate

public void terminate()
Terminates this timer. Be careful. This method returns, before the thread is terminated. If you want to wait for total termination :-), use something like this: myThread.terminate(); myThread.interrupt(); // needed if thread is sleeping myThrad.join();