public class InternalTimerServiceImpl<K,N> extends Object implements InternalTimerService<N>
InternalTimerService
that stores timers on the Java heap.Modifier and Type | Field and Description |
---|---|
protected StreamTaskCancellationContext |
cancellationContext
Context that allows us to stop firing timers if the containing task has been cancelled.
|
protected long |
currentWatermark
The local event time, as denoted by the last received
Watermark . |
protected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> |
eventTimeTimersQueue
Event time timers that are currently in-flight.
|
protected KeyContext |
keyContext |
protected ScheduledFuture<?> |
nextTimer
The one and only Future (if any) registered to execute the next
Triggerable action,
when its (processing) time arrives. |
protected ProcessingTimeService |
processingTimeService |
protected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> |
processingTimeTimersQueue
Processing time timers that are currently in-flight.
|
protected TaskIOMetricGroup |
taskIOMetricGroup |
protected Triggerable<K,N> |
triggerTarget |
Modifier and Type | Method and Description |
---|---|
void |
advanceWatermark(long time) |
long |
currentProcessingTime()
Returns the current processing time.
|
long |
currentWatermark()
Returns the current event-time watermark.
|
void |
deleteEventTimeTimer(N namespace,
long time)
Deletes the timer for the given key and namespace.
|
void |
deleteProcessingTimeTimer(N namespace,
long time)
Deletes the timer for the given key and namespace.
|
void |
forEachEventTimeTimer(BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.
|
void |
forEachProcessingTimeTimer(BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.
|
protected void |
foreachTimer(BiConsumerWithException<N,Long,Exception> consumer,
KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) |
TypeSerializer<K> |
getKeySerializer() |
TypeSerializer<N> |
getNamespaceSerializer() |
int |
numEventTimeTimers() |
int |
numEventTimeTimers(N namespace) |
int |
numProcessingTimeTimers() |
int |
numProcessingTimeTimers(N namespace) |
void |
registerEventTimeTimer(N namespace,
long time)
Registers a timer to be fired when event time watermark passes the given time.
|
void |
registerProcessingTimeTimer(N namespace,
long time)
Registers a timer to be fired when processing time passes the given time.
|
void |
restoreTimersForKeyGroup(InternalTimersSnapshot<?,?> restoredSnapshot,
int keyGroupIdx)
Restore the timers (both processing and event time ones) for a given
keyGroupIdx . |
InternalTimersSnapshot<K,N> |
snapshotTimersForKeyGroup(int keyGroupIdx)
Snapshots the timers (both processing and event time ones) for a given
keyGroupIdx . |
void |
startTimerService(TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer,
Triggerable<K,N> triggerTarget)
Starts the local
InternalTimerServiceImpl by:
Setting the keySerialized and namespaceSerializer for the timers it
will contain. |
boolean |
tryAdvanceWatermark(long time,
InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn) |
protected final ProcessingTimeService processingTimeService
protected final TaskIOMetricGroup taskIOMetricGroup
protected final KeyContext keyContext
protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> processingTimeTimersQueue
protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> eventTimeTimersQueue
protected final StreamTaskCancellationContext cancellationContext
protected long currentWatermark
Watermark
.protected ScheduledFuture<?> nextTimer
Triggerable
action,
when its (processing) time arrives.protected Triggerable<K,N> triggerTarget
public void startTimerService(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, Triggerable<K,N> triggerTarget)
InternalTimerServiceImpl
by:
keySerialized
and namespaceSerializer
for the timers it
will contain.
triggerTarget
which contains the action to be performed when a
timer fires.
This method can be called multiple times, as long as it is called with the same serializers.
public long currentProcessingTime()
InternalTimerService
currentProcessingTime
in interface InternalTimerService<N>
public long currentWatermark()
InternalTimerService
currentWatermark
in interface InternalTimerService<N>
public void registerProcessingTimeTimer(N namespace, long time)
InternalTimerService
registerProcessingTimeTimer
in interface InternalTimerService<N>
public void registerEventTimeTimer(N namespace, long time)
InternalTimerService
registerEventTimeTimer
in interface InternalTimerService<N>
public void deleteProcessingTimeTimer(N namespace, long time)
InternalTimerService
deleteProcessingTimeTimer
in interface InternalTimerService<N>
public void deleteEventTimeTimer(N namespace, long time)
InternalTimerService
deleteEventTimeTimer
in interface InternalTimerService<N>
public void forEachEventTimeTimer(BiConsumerWithException<N,Long,Exception> consumer) throws Exception
InternalTimerService
forEachEventTimeTimer
in interface InternalTimerService<N>
Exception
public void forEachProcessingTimeTimer(BiConsumerWithException<N,Long,Exception> consumer) throws Exception
InternalTimerService
forEachProcessingTimeTimer
in interface InternalTimerService<N>
Exception
protected void foreachTimer(BiConsumerWithException<N,Long,Exception> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) throws Exception
Exception
public boolean tryAdvanceWatermark(long time, InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn) throws Exception
Exception
public InternalTimersSnapshot<K,N> snapshotTimersForKeyGroup(int keyGroupIdx)
keyGroupIdx
.keyGroupIdx
- the id of the key-group to be put in the snapshot.public TypeSerializer<K> getKeySerializer()
public TypeSerializer<N> getNamespaceSerializer()
public void restoreTimersForKeyGroup(InternalTimersSnapshot<?,?> restoredSnapshot, int keyGroupIdx)
keyGroupIdx
.restoredSnapshot
- the restored snapshot containing the key-group's timers, and the
serializers that were used to write themkeyGroupIdx
- the id of the key-group to be put in the snapshot.@VisibleForTesting public int numProcessingTimeTimers()
@VisibleForTesting public int numEventTimeTimers()
@VisibleForTesting public int numProcessingTimeTimers(N namespace)
@VisibleForTesting public int numEventTimeTimers(N namespace)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.