Search in sources :

Example 1 with Tuple3

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);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) Tuple3(org.apache.storm.streams.tuple.Tuple3) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Aggregations

Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)1 StreamBuilder (org.apache.storm.streams.StreamBuilder)1 Tuple3 (org.apache.storm.streams.tuple.Tuple3)1