Jumpi v1.2.0

org.jumpi.spi.component
Interface Timer

All Superinterfaces:
Component, Configurable, Manageable
All Known Implementing Classes:
TimerImpl

public interface Timer
extends Component

A Timer manages one-shot or periodic timers on behalf of TimerListeners. A TimerListener can register its request for interruption at some time in the future with the interruptAt, interruptPeriodically or interruptAfterDelay calls. The TimerListener.handleTimerInterrupt() is called after the timer interval has expired for each TimerListener. Calling this function is termed 'interruption' below, and is unrelated to Thread.interrupt().

A TimerListener can register multiple timers. Each call to register a timer will return a reference to the internal timer. A timer which has not expired can be cancelled by calling cancel(java.lang.Object), giving the timer reference.

See Also:
TimerListener

Method Summary
 void cancel(java.lang.Object timer)
           Cancel a timer which was returned from interruptAt, interruptAfterDelay, or interruptPeriodically Due to multithreading scheduling reality, it is not guaranteed that the TimerListener is not interrupted when cancel is called.
 java.lang.Object interruptAfterDelay(long millisecondsToDelay, TimerListener listener)
          Interrupt the provided TimerListener, once only, after approximately the time interval provided has expired.
 java.lang.Object interruptAt(long time, TimerListener listener)
          Interrupt the provided TimerListener, once only, at approximately the absolute time provided.
 java.lang.Object interruptPeriodically(long period, TimerListener listener, boolean startNow)
          Interrupt the provided TimerListener, periodically, each time after approximately the time interval provided has expired.
 
Methods inherited from interface org.jumpi.spi.Configurable
configure, getName
 
Methods inherited from interface org.jumpi.spi.Manageable
manage
 

Method Detail

interruptAt

public java.lang.Object interruptAt(long time,
                                    TimerListener listener)
Interrupt the provided TimerListener, once only, at approximately the absolute time provided. If the time is in the past, then the interruption will take place as soon as possible. A timer which has not expired may be cancelled.

Parameters:
time - absolute time to interrupt the TimerListener
listener - the TimerListener.
Returns:
a reference to the timer.
See Also:
cancel(java.lang.Object), TimerListener.handleTimerInterrupt()

interruptAfterDelay

public java.lang.Object interruptAfterDelay(long millisecondsToDelay,
                                            TimerListener listener)
Interrupt the provided TimerListener, once only, after approximately the time interval provided has expired. The timer can be cancelled before the time expires.

Parameters:
millisecondsToDelay - milliseconds to pass before interrupting the TimerListener.
listener - the TimerListener.
Returns:
a reference to the timer.
See Also:
cancel(java.lang.Object), TimerListener.handleTimerInterrupt()

interruptPeriodically

public java.lang.Object interruptPeriodically(long period,
                                              TimerListener listener,
                                              boolean startNow)
Interrupt the provided TimerListener, periodically, each time after approximately the time interval provided has expired. The timer can and must be cancelled to stop interruption.

Parameters:
period - the period in milliseconds between each interruption.
listener - the TimerListener.
startNow - whether to interrupt immediately or only after the period.
Returns:
a reference to the timer.
See Also:
cancel(java.lang.Object), TimerListener.handleTimerInterrupt()

cancel

public void cancel(java.lang.Object timer)

Cancel a timer which was returned from interruptAt, interruptAfterDelay, or interruptPeriodically

Due to multithreading scheduling reality, it is not guaranteed that the TimerListener is not interrupted when cancel is called. This particularly when the cancellation takes place at practically the same time as the timer expiry.

Parameters:
timer - The timer instance to cancel.

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.