- java.lang.Object
-
- swim.concurrent.AbstractTimer
-
- All Implemented Interfaces:
Timer,TimerFunction
public abstract class AbstractTimer extends Object implements Timer
Skeletal implementation of a statefulTimer.
-
-
Field Summary
Fields Modifier and Type Field Description protected TimerContexttimerContext
-
Constructor Summary
Constructors Constructor Description AbstractTimer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancancel()Cancels this timer to prevent it from executing.booleanisScheduled()Returnstrueif 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.Scheduleschedule()Returns theScheduleto which this timer is bound.voidsetTimerContext(TimerContext timerContext)Sets the context used to manage thisTimer.TimerContexttimerContext()Returns the context used to manage thisTimer.voidtimerDidCancel()Lifecycle callback invoked after thisTimeris explicitly cancelled.voidtimerWillSchedule(long millis)Lifecycle callback invoked before thisTimeris scheduled for execution.
-
-
-
Field Detail
-
timerContext
protected TimerContext timerContext
-
-
Method Detail
-
timerContext
public final TimerContext timerContext()
Description copied from interface:TimerReturns the context used to manage thisTimer. Returnsnullif thisTimeris not bound to aSchedule.- Specified by:
timerContextin interfaceTimer
-
setTimerContext
public void setTimerContext(TimerContext timerContext)
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
public Schedule 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.
-
-