Class GeneratorSource<T>

java.lang.Object
org.voltdb.stream.source.GeneratorSource<T>
Type Parameters:
T - the type of elements produced by this generator.
All Implemented Interfaces:
VoltLifecycle, VoltStreamSource<T>
Direct Known Subclasses:
IterableSource

public abstract class GeneratorSource<T> extends Object implements VoltStreamSource<T>
Base class for simple sources that generate elements algorithmically.

This class provides a base implementation for generating a stream of data items of type T. Subclasses must implement the next() and hasNext() methods to define the data generation logic.

During processing, the generator emits all available items in one go. After processing, it records emission metrics and cancels further execution to prevent looping.

While the platform may invoke methods on this class from multiple threads it will never do so concurrently and there will be happens-before relationship between the invocations. In other words it will act as thought the invocations were made from a single thread.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.voltdb.metrics.v1.api.Tags
    Tags associated with this source, used for metrics.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    protected abstract boolean
    A way for the implementation to indicate wheter there are more items to generate in the stream.
    protected abstract T
    Implementation should generate the next item in the stream.
    void
    process(long batchId, Consumer<T> consumer, ExecutionContext context)
    Whenever a scheduler has an idle worker it will bind a worker to the source allowing the source to starts processing data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.voltdb.stream.api.pipeline.VoltStreamSource

    commit
  • Field Details

    • sourceTags

      protected org.voltdb.metrics.v1.api.Tags sourceTags
      Tags associated with this source, used for metrics. It associates "source" to the name of the concrete implementation of this class.
  • Constructor Details

    • GeneratorSource

      public GeneratorSource()
  • Method Details

    • next

      protected abstract T next()
      Implementation should generate the next item in the stream.
      Returns:
      the next item of type T
    • hasNext

      protected abstract boolean hasNext()
      A way for the implementation to indicate wheter there are more items to generate in the stream.
      Returns:
      true if there are more items to generate, false otherwise
    • configure

      public void configure(ExecutionContext context)
      Specified by:
      configure in interface VoltLifecycle
    • destroy

      public void destroy(ExecutionContext context)
      Specified by:
      destroy in interface VoltLifecycle
    • process

      public void process(long batchId, Consumer<T> consumer, ExecutionContext context)
      Description copied from interface: VoltStreamSource
      Whenever a scheduler has an idle worker it will bind a worker to the source allowing the source to starts processing data. This method can be called many times and a source implementation must decide to keep producing on cancelling the processing. See ExecutionContext.StreamExecutionContext.cancel() and ExecutionContext.StreamExecutionContext.isCanceled() to control the flow of the stream.

      Once the source has no more data to process the stream will be no longer scheduled and stream processing finishes.

      Specified by:
      process in interface VoltStreamSource<T>
      Parameters:
      batchId - of the current batch
      consumer - a downstream component this source emits data to
      context - runtime context