Package io.aeron.cluster
Interface TimerService
public interface TimerService
Timer service providing API to schedule timers in the Cluster.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCalled from thepoll(long).static interfaceCalled from thesnapshot(TimerSnapshotTaker). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMax number of the timers to expire per singlepoll(long). -
Method Summary
Modifier and TypeMethodDescriptionbooleancancelTimerByCorrelationId(long correlationId) Cancels timer by itscorrelationId.voidcurrentTime(long now) Set the current time from the Cluster in case the underlying implementation depends on it.intpoll(long now) Poll for expired timers.voidscheduleTimerForCorrelationId(long correlationId, long deadline) Schedule timer with the givencorrelationIdanddeadline.voidsnapshot(TimerService.TimerSnapshotTaker snapshotTaker) Takes a snapshot of the timer service state, i.e.
-
Field Details
-
POLL_LIMIT
static final int POLL_LIMITMax number of the timers to expire per singlepoll(long).- See Also:
-
-
Method Details
-
poll
int poll(long now) Poll for expired timers. For each expired timer it invokesTimerService.TimerHandler.onTimerEvent(long)on theTimerService.TimerHandlerthat was provided upon creation of thisTimerServiceinstance. Poll can be terminated early ifPOLL_LIMITis reached or ifTimerService.TimerHandler.onTimerEvent(long)returnsfalse.- Parameters:
now- current time.- Returns:
- number of timers expired, never exceeds
POLL_LIMIT.
-
scheduleTimerForCorrelationId
void scheduleTimerForCorrelationId(long correlationId, long deadline) Schedule timer with the givencorrelationIdanddeadline.- Parameters:
correlationId- to associate with the timer.deadline- when the timer expires.
-
cancelTimerByCorrelationId
boolean cancelTimerByCorrelationId(long correlationId) Cancels timer by itscorrelationId.- Parameters:
correlationId- of the timer to cancel.- Returns:
trueif the timer was cancelled.
-
snapshot
Takes a snapshot of the timer service state, i.e. serializes all non-expired timers.- Parameters:
snapshotTaker- to take a snapshot.
-
currentTime
void currentTime(long now) Set the current time from the Cluster in case the underlying implementation depends on it.- Parameters:
now- the current time.
-