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 processed
O - the type of the accumulator, which must be Comparable 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 Details

    • CancelingFunction

      public CancelingFunction(O accumulator, O threshold, BiFunction<O,I,O> accumulatorFunction)
      Constructs a CancelingFunction 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 accumulator
      threshold - the threshold value at which the execution context should be canceled
      accumulatorFunction - a BiFunction that combines the current accumulator with an input item
  • Method Details

    • process

      public void process(I input, Consumer<I> consumer, ExecutionContext context)
      Description copied from interface: VoltFunction
      processes input and emits output messages to a consumer
      Specified by:
      process in interface VoltFunction<I,O extends Comparable<O>>
      Parameters:
      input - message
      consumer - binds this function with next step
      context - of the execution