Package com.hazelcast.jet.pipeline
Class ServiceFactories
java.lang.Object
com.hazelcast.jet.pipeline.ServiceFactories
Utility class with methods that create several useful
service factories
.- Since:
- Jet 3.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> ServiceFactory<?, IMap<K, V>> iMapService
(String mapName) Returns a factory that provides anIMap
as the service.static <S> ServiceFactory<?,
S> nonSharedService
(FunctionEx<? super Processor.Context, ? extends S> createServiceFn) A variant ofnonSharedService(createFn, destroyFn)
with a no-opdestroyFn
.static <S> ServiceFactory<?,
S> nonSharedService
(FunctionEx<? super Processor.Context, ? extends S> createServiceFn, ConsumerEx<? super S> destroyServiceFn) Returns aServiceFactory
which creates a separate service instance for each parallel Jet processor.static <K,
V> ServiceFactory<?, ReplicatedMap<K, V>> replicatedMapService
(String mapName) Returns a factory that provides aReplicatedMap
as the service object.static <S> ServiceFactory<?,
S> sharedService
(FunctionEx<? super ProcessorSupplier.Context, S> createServiceFn) A variant ofsharedService(createFn, destroyFn)
with a no-opdestroyFn
.static <S> ServiceFactory<?,
S> sharedService
(FunctionEx<? super ProcessorSupplier.Context, S> createServiceFn, ConsumerEx<S> destroyServiceFn) Returns aServiceFactory
which will provide a single shared service object per cluster member.
-
Method Details
-
replicatedMapService
@Nonnull public static <K,V> ServiceFactory<?,ReplicatedMap<K, replicatedMapServiceV>> (@Nonnull String mapName) Returns a factory that provides aReplicatedMap
as the service object. A replicated map is a particularly good choice if you are enriching an event stream with the data stored in the Hazelcast Jet cluster. Unlike in ahashJoin
transformation, the data in the map can change while the job is running so you can keep the enriching dataset up-to-date. UnlikeIMap
, the data you access is local so you won't do any blocking calls using it (important for performance).If you want to destroy the map after the job finishes, call
factory.destroyFn(ReplicatedMap::destroy)
on the object you get from this method.Example usage (without destroyFn):
p.readFrom( /* a batch or streaming source */ ) .mapUsingService(replicatedMapService("fooMapName"), (map, item) -> tuple2(item, map.get(item.getKey()))) .destroyFn(ReplicatedMap::destroy);
- Type Parameters:
K
- type of the map keyV
- type of the map value- Parameters:
mapName
- name of theReplicatedMap
to use as the service- Since:
- Jet 3.0
-
iMapService
Returns a factory that provides anIMap
as the service. This is useful if you are enriching an event stream with the data stored in the Hazelcast Jet cluster. Unlike in ahashJoin
transformation, the data in the map can change while the job is running so you can keep the enriching dataset up-to-date.Instead of using this factory, you can call
GeneralStage.mapUsingIMap(IMap, FunctionEx, BiFunctionEx)
orGeneralStageWithKey.mapUsingIMap(IMap, BiFunctionEx)
.If you plan to use a sync method on the map, call
ServiceFactory.toNonCooperative()
on the returned factory.- Type Parameters:
K
- key typeV
- value type- Parameters:
mapName
- name of the map used as service- Returns:
- the service factory
- Since:
- Jet 3.0
-