Interface SourceFunction.SourceContext<T>

  • Type Parameters:
    T - The type of the elements produced by the source.
    Enclosing interface:
    SourceFunction<T>

    @Public
    public static interface SourceFunction.SourceContext<T>
    Interface that source functions use to emit elements, and possibly watermarks.
    • Method Detail

      • collect

        void collect​(T element)
        Emits one element from the source, without attaching a timestamp. In most cases, this is the default way of emitting elements.

        The element will have no timestamp initially. If timestamps and watermarks are required, for example for event-time windows, timers, or joins, then you need to assign a timestamp via DataStream.assignTimestampsAndWatermarks(WatermarkStrategy) and set a strategy that assigns timestamps (for example using WatermarkStrategy.withTimestampAssigner(TimestampAssignerSupplier)).

        Parameters:
        element - The element to emit
      • collectWithTimestamp

        @PublicEvolving
        void collectWithTimestamp​(T element,
                                  long timestamp)
        Emits one element from the source, and attaches the given timestamp.
        Parameters:
        element - The element to emit
        timestamp - The timestamp in milliseconds since the Epoch
      • emitWatermark

        @PublicEvolving
        void emitWatermark​(Watermark mark)
        Emits the given Watermark. A Watermark of value t declares that no elements with a timestamp t' <= t will occur any more. If further such elements will be emitted, those elements are considered late.
        Parameters:
        mark - The Watermark to emit
      • markAsTemporarilyIdle

        @PublicEvolving
        void markAsTemporarilyIdle()
        Marks the source to be temporarily idle. This tells the system that this source will temporarily stop emitting records and watermarks for an indefinite amount of time.

        Source functions should make a best effort to call this method as soon as they acknowledge themselves to be idle. The system will consider the source to resume activity again once SourceContext#collect(T), SourceContext#collectWithTimestamp(T, long), or emitWatermark(Watermark) is called to emit elements or watermarks from the source.

      • getCheckpointLock

        Object getCheckpointLock()
        Returns the checkpoint lock. Please refer to the class-level comment in SourceFunction for details about how to write a consistent checkpointed source.
        Returns:
        The object to use as the lock
      • close

        void close()
        This method is called by the system to shut down the context.