Package org.voltdb.stream.function
Class CancelingFunction<I,O extends Comparable<O>>
java.lang.Object
org.voltdb.stream.function.CancelingFunction<I,O>
- Type Parameters:
I
- the type of input elements to be processedO
- the type of the accumulator, which must beComparable
to allow threshold comparison
- All Implemented Interfaces:
VoltFunction<I,
,I> VoltLifecycle
public class CancelingFunction<I,O extends Comparable<O>>
extends Object
implements VoltFunction<I,I>
This identity function, but it accumulates value with given
accumulatorFunction
, and cancels the execution
once the accumulated value exceeds given threshold.
Usage Example
// Creating a function that will cancel the execution after processing 1024 bytes worth of strings.
CancelingFunction<String, Integer> cancelingFunction = new CancelingFunction<>(0, 1024, (bytes, string) -> bytes + string.length());
// Use it as a function in a pipeline.
stream
.withName("cancelable infinite stream stream")
.consumeFromSource(...)
.processWith(cancelingFunction)
.terminateWithSink(Sinks.collection());
-
Constructor Summary
ConstructorDescriptionCancelingFunction
(O accumulator, O threshold, BiFunction<O, I, O> accumulatorFunction) Constructs aCancelingFunction
with the specified initial accumulator, threshold, and accumulator function. -
Method Summary
Modifier and TypeMethodDescriptionvoid
process
(I input, Consumer<I> consumer, ExecutionContext context) processes input and emits output messages to a consumerMethods 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.VoltFunction
batchProcessed, initialize, nextBatchStarts
Methods inherited from interface org.voltdb.stream.api.pipeline.VoltLifecycle
configure, destroy
-
Constructor Details
-
CancelingFunction
Constructs aCancelingFunction
with the specified initial accumulator, threshold, and accumulator function.The accumulator function defines how each input item is combined with the current accumulator to produce a new accumulator value. If the updated accumulator meets or exceeds the threshold, the execution context is canceled.
- Parameters:
accumulator
- the initial value of the accumulatorthreshold
- the threshold value at which the execution context should be canceledaccumulatorFunction
- aBiFunction
that combines the current accumulator with an input item
-
-
Method Details
-
process
Description copied from interface:VoltFunction
processes input and emits output messages to a consumer- Specified by:
process
in interfaceVoltFunction<I,
O extends Comparable<O>> - Parameters:
input
- messageconsumer
- binds this function with next stepcontext
- of the execution
-