java.lang.Object
swim.concurrent.AbstractTimer
- All Implemented Interfaces:
Timer,TimerFunction
Skeletal implementation of a stateful
Timer.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Cancels this timer to prevent it from executing.booleanReturnstrueif this timer is currently scheduled to execute.voidreschedule(long millis) Schedules this timer to execute aftermillismilliseconds has elapsed.abstract voidrunTimer()Executes scheduled logic when thisTimerfires.schedule()Returns theScheduleto which this timer is bound.voidsetTimerContext(TimerContext timerContext) Sets the context used to manage thisTimer.final TimerContextReturns the context used to manage thisTimer.voidLifecycle callback invoked after thisTimeris explicitly cancelled.voidtimerWillSchedule(long millis) Lifecycle callback invoked before thisTimeris scheduled for execution.
-
Field Details
-
timerContext
-
-
Constructor Details
-
AbstractTimer
public AbstractTimer()
-
-
Method Details
-
timerContext
Description copied from interface:TimerReturns the context used to manage thisTimer. Returnsnullif thisTimeris not bound to aSchedule.- Specified by:
timerContextin interfaceTimer
-
setTimerContext
Description copied from interface:TimerSets the context used to manage thisTimer. ATimerContextis assigned when binding thisTimerto aSchedule.- Specified by:
setTimerContextin interfaceTimer
-
runTimer
public abstract void runTimer()Description copied from interface:TimerExecutes scheduled logic when thisTimerfires.- Specified by:
runTimerin interfaceTimer- Specified by:
runTimerin interfaceTimerFunction
-
timerWillSchedule
public void timerWillSchedule(long millis) Description copied from interface:TimerLifecycle callback invoked before thisTimeris scheduled for execution.- Specified by:
timerWillSchedulein interfaceTimer
-
timerDidCancel
public void timerDidCancel()Description copied from interface:TimerLifecycle callback invoked after thisTimeris explicitly cancelled.- Specified by:
timerDidCancelin interfaceTimer
-
schedule
Returns theScheduleto which this timer is bound. Delegates to the assignedtimerContext.- Throws:
TimerException- iftimerContextisnull.
-
isScheduled
public boolean isScheduled()Returnstrueif this timer is currently scheduled to execute. Delegates to the assignedtimerContext, if set; otherwise returnsfalse. -
reschedule
public void reschedule(long millis) Schedules this timer to execute aftermillismilliseconds has elapsed. If this timer is currently scheduled, it will not execute at its previously scheduled time; it will only execute at the newly scheduled time. Delegates to the assignedtimerContext.- Throws:
TimerException- iftimerContextisnull, or ifmillisis negative.
-
cancel
public boolean cancel()Cancels this timer to prevent it from executing. Returnstrueif this operation caused the cancellation of this timer; returnsfalseif thisTimerwas not scheduled to execute.
-