Package org.voltdb.stream.source
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
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.
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
Modifier and TypeFieldDescriptionprotected org.voltdb.metrics.v1.api.Tags
Tags associated with this source, used for metrics. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(ExecutionContext context) void
destroy
(ExecutionContext context) protected abstract boolean
hasNext()
A way for the implementation to indicate wheter there are more items to generate in the stream.protected abstract T
next()
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 sourceTagsTags 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
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
- Specified by:
configure
in interfaceVoltLifecycle
-
destroy
- Specified by:
destroy
in interfaceVoltLifecycle
-
process
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. SeeExecutionContext.StreamExecutionContext.cancel()
andExecutionContext.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 interfaceVoltStreamSource<T>
- Parameters:
batchId
- of the current batchconsumer
- a downstream component this source emits data tocontext
- runtime context
-