/** * Convenience for {@link #writeLoggerP(DistributedFunction)} that uses * {@code toString()} as {@code toStringFn}. */ @Nonnull public static ProcessorMetaSupplier writeLoggerP() { return writeLoggerP(Object::toString); }
/** * Returns a sink that logs all the data items it receives, at the INFO * level to the log category {@link * com.hazelcast.jet.impl.connector.WriteLoggerP}. It also logs {@link * com.hazelcast.jet.core.Watermark watermark} items, but at FINE level. * <p> * The sink logs each item on whichever cluster member it happens to * receive it. Its primary purpose is for development, when running Jet on * a local machine. * <p> * The default local parallelism for this sink is 1. * * @param toStringFn a function that returns a string representation of a stream item * @param <T> stream item type */ @Nonnull public static <T> Sink<T> logger(@Nonnull DistributedFunction<? super T, String> toStringFn) { return fromProcessor("loggerSink", writeLoggerP(toStringFn)); }
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(); } } }
Processors.aggregateP(AggregateOperations.toMap(entryKey(), entryValue()))); Vertex hashJoin = dag.newVertex("hashJoin", () -> new HashJoinP<>(Trade::getTicker)); Vertex sink = dag.newVertex("sink", writeLoggerP(o -> Arrays.toString((Object[]) o)));