com.amx.duet.tools.util
Class WaitTimer

java.lang.Object
  extended bycom.amx.duet.util.Timer
      extended bycom.amx.duet.tools.util.WaitTimer

public class WaitTimer
extends com.amx.duet.util.Timer

The WaitTimer class extends the Timer class, which provides API's for creating single value timeouts. The WaitTimer uses a standard listener model interface, TimerListener.

A WaitTimer is created by supplying a TimerListener object, a timeout value in milliseconds and optional repeat value and argument object. Once a WaitTimer is created an ID is automatically assigned to it. WaitTimer are NOT started at construction. The timer commences upon the call to start().

Upon timeout, the TimerListener's handleTimerEvent() is called with the Timer object associated with the timeout passed as a parameter.

WaitTimer are cancelled by calling the cancel() method.

The main difference between the Timer and the WaitTimer classes is that the WaitTimer keeps track of its started state. A call to isStarted() will verify if the timer has been started or not.

Internally, timers are implemented using a single thread. Because of this, processing within the TimerListener handleTimerEvent() should be kept to a minimum as this can affect the accuracy of other timer's in the system.

Since:
AMXTools 1.0.0
Version:
1.0.0

Field Summary
 
Fields inherited from class com.amx.duet.util.Timer
INFINITE, INVALID
 
Constructor Summary
WaitTimer(com.amx.duet.util.TimerListener listener, long timeout)
          Constructs a one-time, non-repeating timer.
WaitTimer(com.amx.duet.util.TimerListener listener, long timeout, int repeat, java.lang.Object argument)
          Constructs a repeatable timer with an optional Object argument.
 
Method Summary
 void cancel()
          Cancels a timer.
 int getTimerID()
          Retrieve's the internal ID value assigned to this timer.
 boolean isStarted()
          Retrieve's the timer's internal started state.
 boolean start()
          Starts a timer.
 
Methods inherited from class com.amx.duet.util.Timer
getArgument, setArgument, setTimeout
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitTimer

public WaitTimer(com.amx.duet.util.TimerListener listener,
                 long timeout)
Constructs a one-time, non-repeating timer.

Parameters:
listener - a TimerListener object that will handle timeout events
timeout - length of timeout in milliseconds

WaitTimer

public WaitTimer(com.amx.duet.util.TimerListener listener,
                 long timeout,
                 int repeat,
                 java.lang.Object argument)
Constructs a repeatable timer with an optional Object argument. The argument is not used for any Timer processing, but is retrievable from the Timer instance through the getArgument() API.

Parameters:
listener - a TimerListener object that will handle timer events
timeout - length of timeout in milliseconds
repeat - number of times the timer should repeat. 0 indicates no repeat, Timer.INFINITE indicates the Timer should repeat until cancelled. For example, a repeat value of 1 will cause the timer to trigger twice.
argument - an Object instance that is retained by the Timer object.
Method Detail

getTimerID

public int getTimerID()
Retrieve's the internal ID value assigned to this timer.

Returns:
int value containing the timer ID.

cancel

public void cancel()
Cancels a timer.


start

public boolean start()
Starts a timer. If the timer's timeout value or listener is invalid, false is returned.

Returns:
status indicating if the timer was started

isStarted

public boolean isStarted()
Retrieve's the timer's internal started state.

Returns:
status indicating if the timer was started


Copyright © 2008 AMX LLC. All Rights Reserved.