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"));
}
}
}
use of org.apache.storm.LocalCluster in project storm by apache.
the class MultipleLoggerTopology method main.
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new TestWordSpout(), 10);
builder.setBolt("exclaim1", new ExclamationLoggingBolt(), 3).shuffleGrouping("word");
builder.setBolt("exclaim2", new ExclamationLoggingBolt(), 2).shuffleGrouping("exclaim1");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(2);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
} else {
try (LocalCluster cluster = new LocalCluster();
LocalTopology topo = cluster.submitTopology("test", conf, builder.createTopology())) {
Utils.sleep(10000);
}
}
}
Aggregations