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 org.apache.flink.runtime.state.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 org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> |
processingTimeTimersQueue
Processing time timers that are currently in-flight.
|
protected org.apache.flink.runtime.metrics.groups.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(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.
|
void |
forEachProcessingTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.
|
protected void |
foreachTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer,
org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) |
org.apache.flink.api.common.typeutils.TypeSerializer<K> |
getKeySerializer() |
org.apache.flink.api.common.typeutils.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(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
org.apache.flink.api.common.typeutils.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 org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup taskIOMetricGroup
protected final KeyContext keyContext
protected final org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> processingTimeTimersQueue
protected final org.apache.flink.runtime.state.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(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.typeutils.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()
InternalTimerServicecurrentProcessingTime in interface InternalTimerService<N>public long currentWatermark()
InternalTimerServicecurrentWatermark in interface InternalTimerService<N>public void registerProcessingTimeTimer(N namespace, long time)
InternalTimerServiceregisterProcessingTimeTimer in interface InternalTimerService<N>public void registerEventTimeTimer(N namespace, long time)
InternalTimerServiceregisterEventTimeTimer in interface InternalTimerService<N>public void deleteProcessingTimeTimer(N namespace, long time)
InternalTimerServicedeleteProcessingTimeTimer in interface InternalTimerService<N>public void deleteEventTimeTimer(N namespace, long time)
InternalTimerServicedeleteEventTimeTimer in interface InternalTimerService<N>public void forEachEventTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer) throws Exception
InternalTimerServiceforEachEventTimeTimer in interface InternalTimerService<N>Exceptionpublic void forEachProcessingTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer) throws Exception
InternalTimerServiceforEachProcessingTimeTimer in interface InternalTimerService<N>Exceptionprotected void foreachTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer, org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) throws Exception
Exceptionpublic boolean tryAdvanceWatermark(long time,
InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn)
throws Exception
Exceptionpublic InternalTimersSnapshot<K,N> snapshotTimersForKeyGroup(int keyGroupIdx)
keyGroupIdx.keyGroupIdx - the id of the key-group to be put in the snapshot.public org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
public org.apache.flink.api.common.typeutils.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–2025 The Apache Software Foundation. All rights reserved.