Package com.hazelcast.jet.pipeline
Class SinkBuilder<C,T>
java.lang.Object
com.hazelcast.jet.pipeline.SinkBuilder<C,T>
- Type Parameters:
C
- type of the context objectT
- type of the items the sink will accept
public final class SinkBuilder<C,T> extends Object
- Since:
- 3.0
-
Method Summary
Modifier and Type Method Description Sink<T>
build()
Creates and returns theSink
with the components you supplied to this builder.SinkBuilder<C,T>
destroyFn(ConsumerEx<? super C> destroyFn)
Sets the function that will destroy the context object and perform any cleanup.SinkBuilder<C,T>
flushFn(ConsumerEx<? super C> flushFn)
Sets the function that implements the sink's flushing behavior.SinkBuilder<C,T>
preferredLocalParallelism(int preferredLocalParallelism)
Sets the local parallelism of the sink.<T_NEW> SinkBuilder<C,T_NEW>
receiveFn(BiConsumerEx<? super C,? super T_NEW> receiveFn)
Sets the function Jet will call upon receiving an item.static <C> SinkBuilder<C,Void>
sinkBuilder(String name, FunctionEx<Processor.Context,? extends C> createFn)
Returns a builder object that offers a step-by-step fluent API to build a customSink
for the Pipeline API.
-
Method Details
-
sinkBuilder
@Nonnull public static <C> SinkBuilder<C,Void> sinkBuilder(@Nonnull String name, @Nonnull FunctionEx<Processor.Context,? extends C> createFn)Returns a builder object that offers a step-by-step fluent API to build a customSink
for the Pipeline API. It allows you to keep a single-threaded and stateful context object, it got from yourcreateFn
, in each instance of a Jet worker dedicated to driving the sink. Its primary intended purpose is to serve as the holder of references to external resources and optional buffers. Keep in mind that only the context object may be stateful; the functions you provide must hold no mutable state of their own.These are the callback functions you can provide to implement the sink's behavior:
-
createFn
creates the context object. Gets the processor context as argument which can be used to obtain local Jet instance, global processor index etc. It will be called once for each worker thread. This component is required. -
onReceiveFn
gets notified of each item the sink receives and (typically) passes it to the context. This component is required. -
flushFn
flushes the context. This component is optional. -
destroyFn
destroys the context. This component is optional.
- Type Parameters:
C
- type of the context object- Since:
- 3.0
-
-
receiveFn
@Nonnull public <T_NEW> SinkBuilder<C,T_NEW> receiveFn(@Nonnull BiConsumerEx<? super C,? super T_NEW> receiveFn)Sets the function Jet will call upon receiving an item. The function receives two arguments: the context object (as provided by thecreateFn
and the received item. Its job is to push the item to the context.- Type Parameters:
T_NEW
- type of the items the sink will accept- Parameters:
receiveFn
- the "add item to the context" function
-
flushFn
Sets the function that implements the sink's flushing behavior. If your context object is buffered, instead of relying on some automatic flushing policy you can provide this function so Jet can choose the best moment to flush.You are not required to provide this function in case your implementation doesn't need it.
- Parameters:
flushFn
- the optional "flush the context" function
-
destroyFn
Sets the function that will destroy the context object and perform any cleanup. The function is called when the job has been completed or cancelled. Jet guarantees that no new items will be received in between the last call toflushFn
and the call todestroyFn
.You are not required to provide this function in case your implementation doesn't need it.
- Parameters:
destroyFn
- the optional "destroy the context object" function
-
preferredLocalParallelism
Sets the local parallelism of the sink. On each member of the cluster Jet will create this many parallel processors for the sink. To identify each processor instance, yourcreateFn
can consultprocContext.totalParallelism()
andprocContext.globalProcessorIndex()
. Jet callscreateFn
exactly once with eachglobalProcessorIndex
from 0 tototalParallelism - 1
.The default value of this property is 1.
-
build
Creates and returns theSink
with the components you supplied to this builder.
-