use of org.apache.storm.streams.tuple.Tuple3 in project storm by apache.
the class TypedTupleExample method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
/**
* The spout emits sequences of (Integer, Long, Long). TupleValueMapper can be used to extract fields
* from the values and produce a stream of typed tuple (Tuple3<Integer, Long, Long> in this case.
*/
Stream<Tuple3<Integer, Long, Long>> stream = builder.newStream(new RandomIntegerSpout(), TupleValueMappers.of(0, 1, 2));
PairStream<Long, Integer> pairs = stream.mapToPair(t -> Pair.of(t._2 / 10000, t._1));
pairs.window(TumblingWindows.of(Count.of(10))).groupByKey().print();
Config config = new Config();
if (args.length > 0) {
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
} else {
try (LocalCluster cluster = new LocalCluster();
LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
Utils.sleep(60_000);
}
}
}
Aggregations