public final class ContextFactories extends Object
context factories
.Modifier and Type | Method and Description |
---|---|
static <K,V> ContextFactory<IMapJet<K,V>> |
iMapContext(String mapName)
Returns a factory that provides an
IMapJet as the context. |
static <K,V> ContextFactory<ReplicatedMap<K,V>> |
replicatedMapContext(String mapName)
Returns a factory that provides a
ReplicatedMap as the context
object. |
@Nonnull public static <K,V> ContextFactory<ReplicatedMap<K,V>> replicatedMapContext(@Nonnull String mapName)
ReplicatedMap
as the context
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 a hashJoin
transformation, the data in the
map can change while the job is running so you can keep the enriching
dataset up-to-date. Unlike IMap
, 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.drawFrom( /* a batch or streaming source */ ) .mapUsingContext(replicatedMapContext("fooMapName"), (map, item) -> tuple2(item, map.get(item.getKey()))) .destroyFn(ReplicatedMap::destroy);
K
- type of the map keyV
- type of the map valuemapName
- name of the ReplicatedMap
to use as the context@Nonnull public static <K,V> ContextFactory<IMapJet<K,V>> iMapContext(@Nonnull String mapName)
IMapJet
as the context. This
is useful if you are enriching an event stream with the data stored in
the Hazelcast Jet cluster. Unlike in a hashJoin
transformation,
the data in the map can change while the job is running so you can keep
the enriching dataset up-to-date.
The downside of accessing an IMap
in a Jet job is that it's a
partitioned data structure, so you'll be accessing remote data and
causing blocking in the stream processing pipeline. This will
significantly reduce the maximum throughput of the job. If you need more
throughput, consider using a ReplicatedMap
as the context or, alternatively, enable the near-cache on
the IMap
.
If you want to destroy the map after the job finishes, call factory.destroyFn(IMap::destroy)
on the object you get from this
method.
Example usage (without destroyFn):
p.drawFrom( /* a batch or streaming source */ ) .mapUsingContext(iMapContext("fooMapName"), (map, item) -> tuple2(item, map.get(item.getKey())));
K
- key typeV
- value typemapName
- name of the map used as contextCopyright © 2018 Hazelcast, Inc.. All rights reserved.