/** * Attaches a {@link #mapUsingContextAsync} stage where the context is a * Hazelcast {@code IMap} with the supplied name. The mapping function will * receive it as the first argument. * <p> * The operations on {@link IMap} typically return Hazelcast's custom * {@link com.hazelcast.core.ICompletableFuture}, not the standard {@link * java.util.concurrent.CompletableFuture}. Use {@link * Util#toCompletableFuture(ICompletableFuture)} to convert them. * <p> * See also {@link GeneralStageWithKey#mapUsingIMapAsync}. * * @param mapName name of the {@code IMap} * @param mapFn the mapping function * @param <K> type of the key in the {@code IMap} * @param <V> type of the value in the {@code IMap} * @param <R> type of the output item * @return the newly attached stage */ @Nonnull default <K, V, R> GeneralStage<R> mapUsingIMapAsync( @Nonnull String mapName, @Nonnull DistributedBiFunction<? super IMap<K, V>, ? super T, ? extends CompletableFuture<R>> mapFn ) { return mapUsingContextAsync(ContextFactories.iMapContext(mapName), mapFn); }
/** * Attaches a {@link #mapUsingContext} stage where the context is a * Hazelcast {@code ReplicatedMap} with the supplied name. The mapping * function will receive it as the first argument. * * @param mapName name of the {@code ReplicatedMap} * @param mapFn the mapping function * @param <K> type of the key in the {@code ReplicatedMap} * @param <V> type of the value in the {@code ReplicatedMap} * @param <R> type of the output item * @return the newly attached stage */ @Nonnull default <K, V, R> GeneralStage<R> mapUsingReplicatedMap( @Nonnull String mapName, @Nonnull DistributedBiFunction<? super ReplicatedMap<K, V>, ? super T, ? extends R> mapFn ) { return mapUsingContext(ContextFactories.replicatedMapContext(mapName), mapFn); }
/** * Attaches a {@link #mapUsingContextAsync} stage where the context is a * Hazelcast {@code IMap} with the supplied name. Jet will use the * specified {@linkplain #keyFn() key function} to retrieve the value from * the map and pass it to the mapping function you supply, as the second * argument. * <p> * This stage is similar to {@link GeneralStage#mapUsingIMapAsync(String, * DistributedBiFunction) stageWithoutKey.mapUsingIMap()}, but here Jet * knows the key and uses it to partition and distribute the input in order * to achieve data locality. The value it fetches from the {@code IMap} is * stored on the cluster member where the processing takes place. However, * if the map doesn't use the default partitioning strategy, the data * locality will be broken. * * @param mapName name of the {@code IMap} * @param mapFn the mapping function * @param <V> type of the value in the {@code IMap} * @param <R> type of the output item * @return the newly attached stage */ @Nonnull default <V, R> GeneralStage<R> mapUsingIMapAsync( @Nonnull String mapName, @Nonnull DistributedBiFunction<? super T, ? super V, ? extends R> mapFn ) { return mapUsingContextAsync(ContextFactories.<K, V>iMapContext(mapName), (map, key, item) -> toCompletableFuture(map.getAsync(key)).thenApply(value -> mapFn.apply(item, value))); }
public static void main(String[] args) { System.setProperty("hazelcast.logging.type", "log4j"); JetInstance instance = Jet.newJetInstance(); Jet.newJetInstance(); try { TickerInfo.populateMap(instance.getHazelcastInstance().getReplicatedMap("tickersInfo")); DAG dag = new DAG(); Vertex tradesSource = dag.newVertex("tradesSource", GenerateTradesP::new); Vertex enrichment = dag.newVertex("enrichment", mapUsingContextP(replicatedMapContext("tickersInfo"), (ReplicatedMap<String, TickerInfo> map, Trade item) -> tuple2(item, map.get(item.getTicker())))); Vertex sink = dag.newVertex("sink", DiagnosticProcessors.writeLoggerP()); tradesSource.localParallelism(1); dag .edge(between(tradesSource, enrichment)) .edge(between(enrichment, sink)); instance.newJob(dag).join(); } finally { Jet.shutdownAll(); } } }
.mapUsingContext(ContextFactories.<TrendKey, Double>iMapContext("trends"), (trendMap, cc) -> { int[] counts = new int[NUM_PREDICTIONS];