Search in sources :

Example 1 with Time

use of com.alibaba.jstorm.window.Time in project jstorm by alibaba.

the class FastWordCountTopNWindowTopology method test.

public static void test() {
    int spout_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
    int split_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPLIT_PARALLELISM_HINT), 1);
    int count_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 1);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new FastRandomSentenceSpout(), spout_Parallelism_hint);
    builder.setBolt("split", new SplitSentence(), split_Parallelism_hint).shuffleGrouping("spout");
    int topN = 10;
    Time win = Time.seconds(10L);
    builder.setBolt("count", new WordCount(topN).timeWindow(win).withStateSize(Time.seconds(120L)), count_Parallelism_hint).fieldsGrouping("split", new Fields("word"));
    builder.setBolt("merge", new MergeTopN(topN).timeWindow(win), 1).allGrouping("count");
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TopologyBuilder(backtype.storm.topology.TopologyBuilder) Time(com.alibaba.jstorm.window.Time) JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)1 Fields (backtype.storm.tuple.Fields)1 Time (com.alibaba.jstorm.window.Time)1 JStormHelper (com.alibaba.starter.utils.JStormHelper)1