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 `context factories`.
  Since:
    3.0

- - ### 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
      Since:
        3.0

    - #### 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.

      Instead of using this factory, you can call `GeneralStage.mapUsingIMap(IMap, FunctionEx, BiFunctionEx)` or `GeneralStageWithKey.mapUsingIMap(IMap, BiFunctionEx)`.

      If you plan to use a sync method on the map, call `ContextFactory.toNonCooperative()` on the returned factory.

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

Copyright © 2019. All rights reserved.