- java.lang.Object
-
- swim.system.agent.AgentTimer
-
- All Implemented Interfaces:
Runnable
,Timer
,TimerContext
,TimerFunction
,TimerRef
public class AgentTimer extends Object implements Timer, TimerContext, TimerRef, Runnable
-
-
Field Summary
Fields Modifier and Type Field Description protected AgentNode
node
protected TimerFunction
timer
protected TimerContext
timerContext
-
Constructor Summary
Constructors Constructor Description AgentTimer(AgentNode node, TimerFunction timer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel()
Cancels the timer to prevent it from executing.boolean
isScheduled()
Returnstrue
if the timer is currently scheduled to execute.void
reschedule(long millis)
Schedules the timer to execute aftermillis
milliseconds has elapsed.void
run()
void
runTimer()
Executes scheduled logic when thisTimer
fires.Schedule
schedule()
Returns theSchedule
to which the timer is bound.void
setTimerContext(TimerContext timerContext)
Sets the context used to manage thisTimer
.TimerContext
timerContext()
Returns the context used to manage thisTimer
.void
timerDidCancel()
Lifecycle callback invoked after thisTimer
is explicitly cancelled.void
timerWillSchedule(long millis)
Lifecycle callback invoked before thisTimer
is scheduled for execution.
-
-
-
Field Detail
-
node
protected final AgentNode node
-
timer
protected final TimerFunction timer
-
timerContext
protected TimerContext timerContext
-
-
Constructor Detail
-
AgentTimer
public AgentTimer(AgentNode node, TimerFunction timer)
-
-
Method Detail
-
timerContext
public TimerContext 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
public void setTimerContext(TimerContext timerContext)
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 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
public Schedule schedule()
Description copied from interface:TimerContext
Returns theSchedule
to which the timer is bound.- Specified by:
schedule
in interfaceTimerContext
-
isScheduled
public boolean isScheduled()
Description copied from interface:TimerContext
Returnstrue
if the timer is currently scheduled to execute.- Specified by:
isScheduled
in interfaceTimerContext
- Specified by:
isScheduled
in interfaceTimerRef
-
reschedule
public void reschedule(long millis)
Description copied from interface:TimerContext
Schedules the timer to execute aftermillis
milliseconds has elapsed. If the timer is currently scheduled, it will not ececute at its previously scheduled time; it will only execute at the newly scheduled time.- Specified by:
reschedule
in interfaceTimerContext
- Specified by:
reschedule
in interfaceTimerRef
-
cancel
public boolean cancel()
Description copied from interface:TimerContext
Cancels the timer to prevent it from executing. Returnstrue
if this operation caused the cancellation of the timer; returnsfalse
if the timer was not scheduled to execute.- Specified by:
cancel
in interfaceTimerContext
- Specified by:
cancel
in interfaceTimerRef
-
-