use of org.apache.storm.LocalCluster in project storm by apache.
the class AggregateExample method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
/**
* Computes average of the stream of numbers emitted by the spout. Internally the per-partition
* sum and counts are accumulated and emitted to a downstream task where the partially accumulated
* results are merged and the final result is emitted.
*/
builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0), 2).window(TumblingWindows.of(BaseWindowedBolt.Duration.seconds(5))).filter(x -> x > 0 && x < 500).aggregate(new Avg()).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);
}
}
}
use of org.apache.storm.LocalCluster in project storm by apache.
the class BranchExample method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
Stream<Integer>[] evenAndOdd = builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0)).branch(x -> (x % 2) == 0, x -> (x % 2) == 1);
evenAndOdd[0].forEach(x -> LOG.info("EVEN> " + x));
evenAndOdd[1].forEach(x -> LOG.info("ODD > " + x));
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);
}
}
}
use of org.apache.storm.LocalCluster in project storm by apache.
the class GroupByKeyAndWindowExample method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// a stream of stock quotes
builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).groupByKeyAndWindow(SlidingWindows.of(Count.of(6), Count.of(3))).print();
// a stream of stock quotes
builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).reduceByKeyAndWindow((x, y) -> x > y ? x : y, SlidingWindows.of(Count.of(6), Count.of(3))).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);
}
}
}
use of org.apache.storm.LocalCluster in project storm by apache.
the class WindowedWordCount method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// A stream of random sentences
builder.newStream(new RandomSentenceSpout(), new ValueMapper<String>(0), 2).window(TumblingWindows.of(Duration.seconds(2))).flatMap(s -> Arrays.asList(s.split(" "))).mapToPair(w -> Pair.of(w, 1)).countByKey().filter(x -> x.getSecond() >= 5).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);
}
}
}
use of org.apache.storm.LocalCluster in project storm by apache.
the class ManualDRPC method main.
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
try (LocalDRPC drpc = new LocalDRPC();
LocalCluster cluster = new LocalCluster()) {
DRPCSpout spout = new DRPCSpout("exclamation", drpc);
builder.setSpout("drpc", spout);
builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
Config conf = new Config();
try (LocalTopology topo = cluster.submitTopology("exclaim", conf, builder.createTopology())) {
System.out.println(drpc.execute("exclamation", "aaa"));
System.out.println(drpc.execute("exclamation", "bbb"));
}
}
}
Aggregations