amber.utility
Class Timer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--amber.utility.Timer
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

public class Timer
extends java.lang.Thread
implements java.io.Serializable

This class is a timer thread used by other classes to get time information.

Version:
1.0.0
Author:
Dr. David J. Knowles
See Also:
TimerInterface, Serialized Form

Field Summary
protected  TimerInterface callback
          The object to call when the timer expires.
protected  long expirationTime
          The time at which the timer expires.
protected  boolean fireOnce
          Set if the timer is to be single shot.
protected  long ticks
          The number of milliseconds to wait.
protected  boolean timerActive
          Set while the timer is active.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Timer(long ticks, TimerInterface callback)
           
Timer(long ticks, TimerInterface callback, boolean fireOnce)
           
 
Method Summary
 long getExpirationTime()
          Returns the time at which the timer will terminate.
 long getTimerDuration()
          The amount of time the timer is running for.
 long getTimeRemaining()
          Returns the time left before the timer expires.
 boolean isTimerActive()
          Returns if the timer is running.
 void resetTimer()
          This function resets the timer.
 void resetTimer(long amount)
          This function resets the timer.
 void run()
          This function loops forever, processing timeouts every once in a while.
 void start()
          This function causes the timer to start operating.
 void startTimer()
          This function causes the timer to start operating.
 void stopTimer()
          This function causes the timer to terminate.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ticks

protected long ticks
The number of milliseconds to wait.

expirationTime

protected long expirationTime
The time at which the timer expires.

callback

protected TimerInterface callback
The object to call when the timer expires.

fireOnce

protected boolean fireOnce
Set if the timer is to be single shot.

timerActive

protected boolean timerActive
Set while the timer is active.
Constructor Detail

Timer

public Timer(long ticks,
             TimerInterface callback,
             boolean fireOnce)
      throws java.lang.IllegalArgumentException

Timer

public Timer(long ticks,
             TimerInterface callback)
      throws java.lang.IllegalArgumentException
Method Detail

start

public void start()
This function causes the timer to start operating.
Overrides:
start in class java.lang.Thread

startTimer

public void startTimer()
This function causes the timer to start operating.

stopTimer

public void stopTimer()
This function causes the timer to terminate. It will do this the next time the timer activates.

isTimerActive

public boolean isTimerActive()
Returns if the timer is running.
Returns:
the state of the timer. The return is true if the timer is operating.

resetTimer

public void resetTimer()
                throws java.lang.IllegalStateException
This function resets the timer. It starts counting from the beginning again. This will only occur if the timer is still operating.
Throws:
java.lang.IllegalStateException - if the timer has stopped.

resetTimer

public void resetTimer(long amount)
                throws java.lang.IllegalStateException
This function resets the timer. It starts counting from the beginning again. This will only occur if the timer is still operating.
Parameters:
amount - long containing the new number of milliseconds to delay for.
Throws:
java.lang.IllegalStateException - if the timer has stopped.

getTimerDuration

public long getTimerDuration()
The amount of time the timer is running for.
Returns:
long containing the number of milliseconds in the timer repeat cycle.

getExpirationTime

public long getExpirationTime()
Returns the time at which the timer will terminate. This is updated every time the timer repeats.
Returns:
long expiration time for the timer.

getTimeRemaining

public long getTimeRemaining()
Returns the time left before the timer expires.
Returns:
long time remaining in the timer.

run

public void run()
This function loops forever, processing timeouts every once in a while. This should not be invoked directly. Use the startTimer function to initiate the timer.
Overrides:
run in class java.lang.Thread
See Also:
startTimer(), stopTimer()


Copyright © 2002 Clearfield Research Ltd. All Rights Reserved.