@SuppressWarnings("deprecation")
public class CassandraReachTopology {
public static void main(String[] args) throws Exception {
LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("reach");
Config config = new Config();
String configKey = "cassandra-config";
HashMap<String, Object> clientConfig = new HashMap<String, Object>();
clientConfig.put(StormCassandraConstants.CASSANDRA_HOST, "localhost:9160");
clientConfig.put(StormCassandraConstants.CASSANDRA_KEYSPACE, Arrays.asList(new String [] {"stormks"}));
config.put(configKey, clientConfig);
// DelimitedColumnLookupBolt tweetersBolt =
// new DelimitedColumnLookupBolt("tweeters_delimited", "rowKey",
// "tweeted_by", ":", "rowKey", "tweeter", true);
//
// DelimitedColumnLookupBolt followersBolt =
// new DelimitedColumnLookupBolt("followers_delimited", "tweeter",
// "followers", ":", "rowKey", "follower", true);
// cf = "tweeters", rowkey = tuple["url"]
TupleMapper<String, String, String> tweetersTupleMapper = new DefaultTupleMapper("stormks", "tweeters", "url");
// cf (url -> tweeters) -> emit(url, follower)
ColumnMapper<String, String, String> tweetersColumnsMapper = new ValuelessColumnsMapper("url", "tweeter", true);
CassandraLookupBolt<String, String, String> tweetersBolt = new CassandraLookupBolt<String, String, String>(configKey,
tweetersTupleMapper, tweetersColumnsMapper);
// cf = "followers", rowkey = tuple["tweeter"]
TupleMapper<String, String, String> followersTupleMapper = new DefaultTupleMapper("stormks", "followers", "tweeter");
// cf (tweeter -> followers) ==> emit(url, follower)
ValuelessColumnsMapper followersColumnsMapper = new ValuelessColumnsMapper("url", "follower", true);
CassandraLookupBolt<String, String, String> followersBolt = new CassandraLookupBolt<String, String, String>(configKey,
followersTupleMapper, followersColumnsMapper);
builder.addBolt(new InitBolt());
builder.addBolt(tweetersBolt).shuffleGrouping();
builder.addBolt(followersBolt).shuffleGrouping();
builder.addBolt(new PartialUniquer()).fieldsGrouping(new Fields("id", "follower"));
builder.addBolt(new CountAggregator()).fieldsGrouping(new Fields("id"));
if (args == null || args.length == 0) {
config.setMaxTaskParallelism(3);
LocalDRPC drpc = new LocalDRPC();
LocalCluster cluster = new LocalCluster();
if ("true".equals(System.getProperty("debug"))) {
config.setDebug(true);
}
cluster.submitTopology("reach-drpc", config, builder.createLocalTopology(drpc));
String[] urlsToTry = new String[] { "http://github.com/hmsonline", "http://github.com/nathanmarz",
"http://github.com/ptgoetz", "http://github.com/boneill" };
for (String url : urlsToTry) {
System.out.println("Reach of " + url + ": " + drpc.execute("reach", url));
}
cluster.shutdown();
drpc.shutdown();
} else {
config.setNumWorkers(6);
StormSubmitter.submitTopology(args[0], config, builder.createRemoteTopology());
}
}