Class InternalTimerServiceImpl<K,N>

java.lang.Object
org.apache.flink.streaming.api.operators.InternalTimerServiceImpl<K,N>
All Implemented Interfaces:
InternalTimerService<N>
Direct Known Subclasses:
InternalTimerServiceAsyncImpl

public class InternalTimerServiceImpl<K,N> extends Object implements InternalTimerService<N>
InternalTimerService that stores timers on the Java heap.
  • Field Details

  • Method Details

    • startTimerService

      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)
      Starts the local InternalTimerServiceImpl by:
      1. Setting the keySerialized and namespaceSerializer for the timers it will contain.
      2. Setting the triggerTarget which contains the action to be performed when a timer fires.
      3. Re-registering timers that were retrieved after recovering from a node failure, if any.

      This method can be called multiple times, as long as it is called with the same serializers.

    • currentProcessingTime

      public long currentProcessingTime()
      Description copied from interface: InternalTimerService
      Returns the current processing time.
      Specified by:
      currentProcessingTime in interface InternalTimerService<K>
    • currentWatermark

      public long currentWatermark()
      Description copied from interface: InternalTimerService
      Returns the current event-time watermark.
      Specified by:
      currentWatermark in interface InternalTimerService<K>
    • registerProcessingTimeTimer

      public void registerProcessingTimeTimer(N namespace, long time)
      Description copied from interface: InternalTimerService
      Registers a timer to be fired when processing time passes the given time. The namespace you pass here will be provided when the timer fires.
      Specified by:
      registerProcessingTimeTimer in interface InternalTimerService<K>
    • registerEventTimeTimer

      public void registerEventTimeTimer(N namespace, long time)
      Description copied from interface: InternalTimerService
      Registers a timer to be fired when event time watermark passes the given time. The namespace you pass here will be provided when the timer fires.
      Specified by:
      registerEventTimeTimer in interface InternalTimerService<K>
    • deleteProcessingTimeTimer

      public void deleteProcessingTimeTimer(N namespace, long time)
      Description copied from interface: InternalTimerService
      Deletes the timer for the given key and namespace.
      Specified by:
      deleteProcessingTimeTimer in interface InternalTimerService<K>
    • deleteEventTimeTimer

      public void deleteEventTimeTimer(N namespace, long time)
      Description copied from interface: InternalTimerService
      Deletes the timer for the given key and namespace.
      Specified by:
      deleteEventTimeTimer in interface InternalTimerService<K>
    • forEachEventTimeTimer

      public void forEachEventTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer) throws Exception
      Description copied from interface: InternalTimerService
      Performs an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.
      Specified by:
      forEachEventTimeTimer in interface InternalTimerService<K>
      Throws:
      Exception
    • forEachProcessingTimeTimer

      public void forEachProcessingTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer) throws Exception
      Description copied from interface: InternalTimerService
      Performs an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.
      Specified by:
      forEachProcessingTimeTimer in interface InternalTimerService<K>
      Throws:
      Exception
    • foreachTimer

      protected void foreachTimer(org.apache.flink.util.function.BiConsumerWithException<N,Long,Exception> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) throws Exception
      Throws:
      Exception
    • advanceWatermark

      public void advanceWatermark(long time) throws Exception
      Throws:
      Exception
    • tryAdvanceWatermark

      public boolean tryAdvanceWatermark(long time, InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn) throws Exception
      Returns:
      true if following watermarks can be processed immediately. False if the firing timers should be interrupted as soon as possible.
      Throws:
      Exception
    • snapshotTimersForKeyGroup

      public InternalTimersSnapshot<K,N> snapshotTimersForKeyGroup(int keyGroupIdx)
      Snapshots the timers (both processing and event time ones) for a given keyGroupIdx.
      Parameters:
      keyGroupIdx - the id of the key-group to be put in the snapshot.
      Returns:
      a snapshot containing the timers for the given key-group, and the serializers for them
    • getKeySerializer

      public org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
    • getNamespaceSerializer

      public org.apache.flink.api.common.typeutils.TypeSerializer<N> getNamespaceSerializer()
    • restoreTimersForKeyGroup

      public void restoreTimersForKeyGroup(InternalTimersSnapshot<?,?> restoredSnapshot, int keyGroupIdx)
      Restore the timers (both processing and event time ones) for a given keyGroupIdx.
      Parameters:
      restoredSnapshot - the restored snapshot containing the key-group's timers, and the serializers that were used to write them
      keyGroupIdx - the id of the key-group to be put in the snapshot.
    • numProcessingTimeTimers

      @VisibleForTesting public int numProcessingTimeTimers()
    • numEventTimeTimers

      @VisibleForTesting public int numEventTimeTimers()
    • numProcessingTimeTimers

      @VisibleForTesting public int numProcessingTimeTimers(N namespace)
    • numEventTimeTimers

      @VisibleForTesting public int numEventTimeTimers(N namespace)