Class ServiceFactory<C,​S>

java.lang.Object
com.hazelcast.jet.pipeline.ServiceFactory<C,​S>
Type Parameters:
C - type of the shared context object
S - type of the service object
All Implemented Interfaces:
Serializable, Cloneable

public final class ServiceFactory<C,​S>
extends Object
implements Serializable, Cloneable
A holder of functions needed to create and destroy a service object used in pipeline transforms such as stage.mapUsingService().

The lifecycle of this factory object is as follows:

  1. When you submit a job, Jet serializes ServiceFactory and sends it to all the cluster members.
  2. On each member Jet calls createContextFn() to get a context object that will be shared across all the service instances on that member. For example, if you are connecting to an external service that provides a thread-safe client, you can create it here and then create individual sessions for each service instance.
  3. Jet repeatedly calls createServiceFn() to create as many service instances on each member as determined by the localParallelism of the pipeline stage. The invocations of createServiceFn() receive the context object.
  4. When the job is done, Jet calls destroyServiceFn() with each service instance.
  5. Finally, Jet calls destroyContextFn() with the context object.
If you don't need the member-wide context object, you can call the simpler methods ServiceFactories.nonSharedService(FunctionEx, ConsumerEx) ServiceFactories.processorLocalService} or ServiceFactories.sharedService(FunctionEx, ConsumerEx) ServiceFactories.memberLocalService}.

Here's a list of pipeline transforms that require a ServiceFactory:

Since:
4.0
See Also:
Serialized Form