@Managed public class TimerNotifier extends java.lang.Object
Timer Notifier
The TimerNotifier provides timer control and a user provided notification operation, timerNotify().
Multiple timers may be started against a single instance of a TimerNotifier.
The life cycle of the notifier is controlled by the user. If a timer fires on a notifier that has been deleted by the user, the timer will be automatically canceled.
Constructor and Description |
---|
TimerNotifier()
Create a new TimerNotifier
|
Modifier and Type | Method and Description |
---|---|
void |
cancel(java.lang.String timerId)
Cancel the timer
|
Result |
highResolutionReset(java.lang.String timerId,
int milliseconds)
Reset the timer expiration time
|
java.lang.String |
highResolutionStartOneShot(int milliseconds,
java.lang.Object object)
Start a timer that fires once
|
java.lang.String |
highResolutionStartRecurring(int milliseconds,
java.lang.Object object)
Start a timer that fires multiple times
|
Result |
reset(java.lang.String timerId,
int seconds)
Reset the timer expiration time
|
java.lang.String |
startOneShot(int seconds,
java.lang.Object object)
Start a timer that fires once
|
java.lang.String |
startRecurring(int seconds,
java.lang.Object object)
Start a timer that fires multiple times
|
void |
timerNotify(java.lang.String timerId,
java.lang.Object object)
Called when a timer fires
|
public TimerNotifier()
public final java.lang.String startOneShot(int seconds, java.lang.Object object)
Start a timer that fires once
seconds
- The number of seconds before
this timer should fire.object
- Object handle to be passed
to the timer notifier
when the timer fires.Starts a timer that will fire once, at least "seconds" seconds from now. The TimerId result and the object parameter will be passed to the timerNotify operation when the timer fires.
public final java.lang.String startRecurring(int seconds, java.lang.Object object)
Start a timer that fires multiple times
seconds
- The number of seconds before
this timer should fire.object
- Object handle to be passed
to the timer notifier
when the timer fires.Starts a timer that will fire every "seconds" seconds, starting "seconds" seconds from now. The TimerId result and the object parameter will be passed to the timerNotify operation when the timer fires.
public final Result reset(java.lang.String timerId, int seconds)
Reset the timer expiration time
timerId
- The ID of the timer to resetseconds
- The number of seconds to
rest the timer to.Resets the expiration time on an existing timer to "seconds" seconds from now.
Ok is returned if the timer was found and reset. Otherwise Fail is returned.
public final java.lang.String highResolutionStartOneShot(int milliseconds, java.lang.Object object)
Start a timer that fires once
milliseconds
- The number of milliseconds before
this timer should fire.object
- Object handle to be passed
to the timer notifier
when the timer fires.Starts a timer that will fire once, at least "milliseconds" milliseconds from now. The TimerId result and the object parameter will be passed to the timerNotify operation when the timer fires.
Warnings: The timer resolution is dependent upon the current setting of the timerResolutionMilliseconds
public final java.lang.String highResolutionStartRecurring(int milliseconds, java.lang.Object object)
Start a timer that fires multiple times
milliseconds
- The number of milliseconds
before this timer should fire.object
- Object handle to be passed
to the timer notifier
when the timer fires.Starts a timer that will fire every "milliseconds" milliseconds, starting "milliseconds" milliseconds from now. The TimerId result and the object parameter will be passed to the timerNotify operation when the timer fires.
Warnings: The timer resolution is dependent upon the current setting of the timerResolutionMilliseconds configuration value.
public final Result highResolutionReset(java.lang.String timerId, int milliseconds)
Reset the timer expiration time
timerId
- The ID of the timer to resetmilliseconds
- The number of milliseconds to
reset the timer to.Resets the expiration time on an existing timer to "seconds" seconds from now.
Ok is returned if the timer was found and reset. Otherwise Fail is returned.
Warnings: The timer resolution is dependent upon the current setting of the timerResolutionMilliseconds
public final void cancel(java.lang.String timerId)
Cancel the timer
timerId
- ID of the timer to cancel.
Cancels an existing timer.
This operation returns void because there are inherent race conditions when canceling timers in multi-threaded systems. It is possible for one (or even more in very busy systems) timer notifications to arrive after the cancel has completed.
The application calling cancel (on one thread/CPU) may be occurring simultaneously with the timer service thread (on another thread/CPU) executing the timer notification. Another possibility is that the timer service has queued one or more notifications that haven't yet been serviced due to CPU starvation.
public void timerNotify(java.lang.String timerId, java.lang.Object object)
Called when a timer fires
object
- The object handle that was
passed to the timer start
operation.timerId
- The ID that was returned from
the timer start operation.
This operation must be implemented by in the callers interface, derived from swtimer::TimerNotifier.
It is invoked by the timer service when a timer fires.