- java.lang.Object
-
- swim.runtime.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 AgentNodenodeprotected TimerFunctiontimerprotected TimerContexttimerContext
-
Constructor Summary
Constructors Constructor Description AgentTimer(AgentNode node, TimerFunction timer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel()Cancels the timer to prevent it from executing.booleanisScheduled()Returnstrueif the timer is currently scheduled to execute.voidreschedule(long millis)Schedules the timer to execute aftermillismilliseconds has elapsed.voidrun()voidrunTimer()Executes scheduled logic when thisTimerfires.Scheduleschedule()Returns theScheduleto which the 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
-
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: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 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()
Description copied from interface:TimerContextReturns theScheduleto which the timer is bound.- Specified by:
schedulein interfaceTimerContext
-
isScheduled
public boolean isScheduled()
Description copied from interface:TimerContextReturnstrueif the timer is currently scheduled to execute.- Specified by:
isScheduledin interfaceTimerContext- Specified by:
isScheduledin interfaceTimerRef
-
reschedule
public void reschedule(long millis)
Description copied from interface:TimerContextSchedules the timer to execute aftermillismilliseconds 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:
reschedulein interfaceTimerContext- Specified by:
reschedulein interfaceTimerRef
-
cancel
public boolean cancel()
Description copied from interface:TimerContextCancels the timer to prevent it from executing. Returnstrueif this operation caused the cancellation of the timer; returnsfalseif the timer was not scheduled to execute.- Specified by:
cancelin interfaceTimerContext- Specified by:
cancelin interfaceTimerRef
-
-