use of udacity.storm.spout.RandomSentenceSpout in project ud381 by udacity.
the class SentenceCountTopology method main.
public static void main(String[] args) throws Exception {
// create the topology
TopologyBuilder builder = new TopologyBuilder();
// attach the word spout to the topology - parallelism of 5
// builder.setSpout("word-spout", new WordSpout(), 5);
// attach sentence spout to the topology - parallelism of 1
builder.setSpout("sentence-spout", new RandomSentenceSpout(), 1);
// attach the count bolt using fields grouping - parallelism of 15
builder.setBolt("count-bolt", new CountBolt(), 15).fieldsGrouping("sentence-spout", new Fields("sentence"));
// attach the report bolt using global grouping - parallelism of 1
// ***************************************************
// BEGIN YOUR CODE - part 2
builder.setBolt("report-bolt", new ReportBolt(), 1).globalGrouping("count-bolt");
// END YOUR CODE
// ***************************************************
// create the default config object
Config conf = new Config();
// set the config in debugging mode
conf.setDebug(true);
if (args != null && args.length > 0) {
// run it in a live cluster
// set the number of workers for running all spout and bolt tasks
conf.setNumWorkers(3);
// create the topology and submit with config
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
// run it in a simulated local cluster
// set the number of threads to run - similar to setting number of workers in live cluster
conf.setMaxTaskParallelism(3);
// create the local cluster instance
LocalCluster cluster = new LocalCluster();
// submit the topology to the local cluster
// name topology
cluster.submitTopology("sentence-count", conf, builder.createTopology());
// **********************************************************************
// let the topology run for 30 seconds. note topologies never terminate!
Thread.sleep(30000);
// **********************************************************************
// we are done, so shutdown the local cluster
cluster.shutdown();
}
}
use of udacity.storm.spout.RandomSentenceSpout in project ud381 by udacity.
the class SentenceWordCountTopology method main.
public static void main(String[] args) throws Exception {
// create the topology
TopologyBuilder builder = new TopologyBuilder();
// attach the word spout to the topology - parallelism of 5
// builder.setSpout("word-spout", new WordSpout(), 5);
// attach sentence spout to the topology - parallelism of 1
builder.setSpout("sentence-spout", new RandomSentenceSpout(), 1);
// attach split sentence split bolt to topology - parallelism of 15
// builder.setBolt("split-sentence-bolt", new SplitSentenceBolt(), 15).fieldsGrouping("sentence-spout", new Fields("sentence"));
builder.setBolt("split-sentence-bolt", new SplitSentenceBolt(), 15).shuffleGrouping("sentence-spout");
// attach the count bolt using fields grouping - parallelism of 15
builder.setBolt("count-bolt", new CountBolt(), 15).fieldsGrouping("split-sentence-bolt", new Fields("sentence-word"));
// attach the report bolt using global grouping - parallelism of 1
// ***************************************************
// BEGIN YOUR CODE - part 2
builder.setBolt("report-bolt", new ReportBolt(), 1).globalGrouping("count-bolt");
// END YOUR CODE
// ***************************************************
// create the default config object
Config conf = new Config();
// set the config in debugging mode
conf.setDebug(true);
if (args != null && args.length > 0) {
// run it in a live cluster
// set the number of workers for running all spout and bolt tasks
conf.setNumWorkers(3);
// create the topology and submit with config
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
// run it in a simulated local cluster
// set the number of threads to run - similar to setting number of workers in live cluster
conf.setMaxTaskParallelism(3);
// create the local cluster instance
LocalCluster cluster = new LocalCluster();
// submit the topology to the local cluster
// name topology
cluster.submitTopology("sentence-word-count", conf, builder.createTopology());
// **********************************************************************
// let the topology run for 30 seconds. note topologies never terminate!
Thread.sleep(30000);
// **********************************************************************
// we are done, so shutdown the local cluster
cluster.shutdown();
}
}
Aggregations