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 TypeMethodDescriptionboolean
cancel()
Cancels this timer to prevent it from executing.boolean
Returnstrue
if this timer is currently scheduled to execute.void
reschedule
(long millis) Schedules this timer to execute aftermillis
milliseconds has elapsed.abstract void
runTimer()
Executes scheduled logic when thisTimer
fires.schedule()
Returns theSchedule
to which this timer is bound.void
setTimerContext
(TimerContext timerContext) Sets the context used to manage thisTimer
.final TimerContext
Returns the context used to manage thisTimer
.void
Lifecycle callback invoked after thisTimer
is explicitly cancelled.void
timerWillSchedule
(long millis) Lifecycle callback invoked before thisTimer
is scheduled for execution.
-
Field Details
-
timerContext
-
-
Constructor Details
-
AbstractTimer
public AbstractTimer()
-
-
Method Details
-
timerContext
Description copied from interface:Timer
Returns the context used to manage thisTimer
. Returnsnull
if thisTimer
is not bound to aSchedule
.- Specified by:
timerContext
in interfaceTimer
-
setTimerContext
Description copied from interface:Timer
Sets the context used to manage thisTimer
. ATimerContext
is assigned when binding thisTimer
to aSchedule
.- Specified by:
setTimerContext
in interfaceTimer
-
runTimer
public abstract void runTimer()Description copied from interface:Timer
Executes scheduled logic when thisTimer
fires.- Specified by:
runTimer
in interfaceTimer
- Specified by:
runTimer
in interfaceTimerFunction
-
timerWillSchedule
public void timerWillSchedule(long millis) Description copied from interface:Timer
Lifecycle callback invoked before thisTimer
is scheduled for execution.- Specified by:
timerWillSchedule
in interfaceTimer
-
timerDidCancel
public void timerDidCancel()Description copied from interface:Timer
Lifecycle callback invoked after thisTimer
is explicitly cancelled.- Specified by:
timerDidCancel
in interfaceTimer
-
schedule
Returns theSchedule
to which this timer is bound. Delegates to the assignedtimerContext
.- Throws:
TimerException
- iftimerContext
isnull
.
-
isScheduled
public boolean isScheduled()Returnstrue
if 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 aftermillis
milliseconds 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
- iftimerContext
isnull
, or ifmillis
is negative.
-
cancel
public boolean cancel()Cancels this timer to prevent it from executing. Returnstrue
if this operation caused the cancellation of this timer; returnsfalse
if thisTimer
was not scheduled to execute.
-