C
- the user-defined context object typepublic final class ContextFactory<C> extends Object implements Serializable
JetInstance
. Among others, this gives you the ability to
interact with IMDG data structures such as IMap
and ReplicatedMap
during the transformation.
You can use the context factory from these Pipeline API methods:
GeneralStage.mapUsingContext(com.hazelcast.jet.pipeline.ContextFactory<C>, com.hazelcast.jet.function.DistributedBiFunction<? super C, ? super T, ? extends R>)
GeneralStage.filterUsingContext(com.hazelcast.jet.pipeline.ContextFactory<C>, com.hazelcast.jet.function.DistributedBiPredicate<? super C, ? super T>)
GeneralStage.flatMapUsingContext(com.hazelcast.jet.pipeline.ContextFactory<C>, com.hazelcast.jet.function.DistributedBiFunction<? super C, ? super T, ? extends com.hazelcast.jet.Traverser<? extends R>>)
ContextFactories
or create your own using the builder you get
by calling withCreateFn(com.hazelcast.jet.function.DistributedFunction<com.hazelcast.jet.JetInstance, ? extends C>)
. The factory instances must be
immutable.Modifier and Type | Method and Description |
---|---|
DistributedFunction<JetInstance,? extends C> |
createFn()
Returns the create-function.
|
DistributedConsumer<? super C> |
destroyFn()
Returns the destroy-function.
|
boolean |
isCooperative()
Returns the
isCooperative flag. |
boolean |
isSharedLocally()
Returns the
isSharedLocally flag. |
ContextFactory<C> |
nonCooperative()
Returns a copy of this
ContextFactory with the isCooperative
flag set to false . |
ContextFactory<C> |
shareLocally()
Returns a copy of this
ContextFactory with the shareLocally
flag set to true . |
static <C> ContextFactory<C> |
withCreateFn(DistributedFunction<JetInstance,? extends C> createContextFn)
Creates a new
ContextFactory with the given create-function. |
ContextFactory<C> |
withDestroyFn(DistributedConsumer<? super C> destroyFn)
Returns a copy of this
ContextFactory with the destory-function
replaced with the given function. |
@Nonnull public static <C> ContextFactory<C> withCreateFn(@Nonnull DistributedFunction<JetInstance,? extends C> createContextFn)
ContextFactory
with the given create-function.C
- the user-defined context object typecreateContextFn
- the function to create new context object, given a JetInstance@Nonnull public ContextFactory<C> withDestroyFn(@Nonnull DistributedConsumer<? super C> destroyFn)
ContextFactory
with the destory-function
replaced with the given function.destroyFn
- the function to destroy user-defined context. It will be called
when the job finishes@Nonnull public ContextFactory<C> nonCooperative()
ContextFactory
with the isCooperative
flag set to false
. The context factory is cooperative by default.
Call this method if any of the calls to the methods in the context may block
or otherwise take long to complete.
The contract of cooperative multithreading is described here
.
isCooperative
flag set to false
.@Nonnull public ContextFactory<C> shareLocally()
ContextFactory
with the shareLocally
flag set to true
. By default the context object is not shared so each
parallel processor gets its own instance. If you enable sharing, the context
object will be used from multiple threads — make sure that it is
thread-safe.isSharedLocally
flag set.@Nonnull public DistributedFunction<JetInstance,? extends C> createFn()
@Nonnull public DistributedConsumer<? super C> destroyFn()
public boolean isCooperative()
isCooperative
flag.public boolean isSharedLocally()
isSharedLocally
flag.Copyright © 2018 Hazelcast, Inc.. All rights reserved.