com.hazelcast.jet.pipeline

## Class ContextFactories

- java.lang.Object
- - com.hazelcast.jet.pipeline.ContextFactories

-     public final class ContextFactories
      extends Object

  Utility class with methods that create several useful kinds of `context factories`.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### replicatedMapContext

          @Nonnull
          public static <K,V> ContextFactory<ReplicatedMap<K,V>> replicatedMapContext(@Nonnull
                                                                                               String mapName)

      Returns a factory that provides a `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);

      Type Parameters:
        `K` - type of the map key
        `V` - type of the map value
      Parameters:
        `mapName` - name of the `ReplicatedMap` to use as the context

    - #### iMapContext

          @Nonnull
          public static <K,V> ContextFactory<IMapJet<K,V>> iMapContext(@Nonnull
                                                                                String mapName)

      Returns a factory that provides an `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())));

      Type Parameters:
        `K` - key type
        `V` - value type
      Parameters:
        `mapName` - name of the map used as context
      Returns:
        the context factory

Copyright © 2018. All rights reserved.