Search in sources :

Example 21 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project incubator-heron by apache.

the class WindowedBoltExecutor method newWindowLifecycleListener.

protected WindowLifecycleListener<Tuple> newWindowLifecycleListener() {
    return new WindowLifecycleListener<Tuple>() {

        @Override
        public void onExpiry(List<Tuple> tuples) {
            for (Tuple tuple : tuples) {
                windowedOutputCollector.ack(tuple);
            }
        }

        @Override
        public void onActivation(List<Tuple> tuples, List<Tuple> newTuples, List<Tuple> expiredTuples, Long timestamp) {
            windowedOutputCollector.setContext(tuples);
            boltExecute(tuples, newTuples, expiredTuples, timestamp);
        }
    };
}
Also used : WindowLifecycleListener(com.twitter.heron.api.windowing.WindowLifecycleListener) List(java.util.List) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 22 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project incubator-heron by apache.

the class TopologyManagerTest method getTestTopology.

/**
 * Construct the test topology
 */
public static TopologyAPI.Topology getTestTopology() {
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout(STREAM_ID, new BaseRichSpout() {

        private static final long serialVersionUID = 5406114907377311020L;

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
            outputFieldsDeclarer.declare(new Fields(STREAM_ID));
        }

        @Override
        public void open(Map<String, Object> map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
        }

        @Override
        public void nextTuple() {
        }
    }, 2);
    topologyBuilder.setBolt(BOLT_ID, new BaseBasicBolt() {

        private static final long serialVersionUID = 4398578755681473899L;

        @Override
        public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
        }

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        }
    }, 2).shuffleGrouping(STREAM_ID);
    Config conf = new Config();
    conf.setDebug(true);
    conf.setMaxSpoutPending(10);
    conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError");
    conf.setComponentRam(STREAM_ID, ByteAmount.fromMegabytes(500));
    conf.setComponentRam(BOLT_ID, ByteAmount.fromGigabytes(1));
    conf.setMessageTimeoutSecs(1);
    return topologyBuilder.createTopology().setName("topology-name").setConfig(conf).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) Config(com.twitter.heron.api.Config) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) Fields(com.twitter.heron.api.tuple.Fields) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Example 23 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project streaming-samples by ashvina.

the class TotalRanker method execute.

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    restriction.execute();
    Rankings partialRank = (Rankings) tuple.getValueByField(FIELD_RANKING);
    rankings.updateWith(partialRank);
    if (System.currentTimeMillis() - previousEmitTime > emitRate.toMillis()) {
        String result = rankings.getRankings().stream().map(trend -> trend.getObject() + ":" + trend.getCount()).collect(Collectors.joining(", "));
        System.out.println(result);
        previousEmitTime = System.currentTimeMillis();
    }
}
Also used : Rankings(org.apache.storm.starter.tools.Rankings) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) FIELD_RANKING(com.github.ashvina.heron.trending.TopTrendingTopology.FIELD_RANKING) Duration(java.time.Duration) Map(java.util.Map) Fields(com.twitter.heron.api.tuple.Fields) BaseRateLimitedBolt(com.github.ashvina.heron.BaseRateLimitedBolt) Tuple(com.twitter.heron.api.tuple.Tuple) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) Collectors(java.util.stream.Collectors) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Rankings(org.apache.storm.starter.tools.Rankings)

Aggregations

Tuple (com.twitter.heron.api.tuple.Tuple)23 TopologyContext (com.twitter.heron.api.topology.TopologyContext)11 Fields (com.twitter.heron.api.tuple.Fields)10 Values (com.twitter.heron.api.tuple.Values)8 BasicOutputCollector (com.twitter.heron.api.bolt.BasicOutputCollector)7 OutputFieldsDeclarer (com.twitter.heron.api.topology.OutputFieldsDeclarer)7 TopologyBuilder (com.twitter.heron.api.topology.TopologyBuilder)7 HashMap (java.util.HashMap)7 BaseBasicBolt (com.twitter.heron.api.bolt.BaseBasicBolt)6 BaseRichSpout (com.twitter.heron.api.spout.BaseRichSpout)6 SpoutOutputCollector (com.twitter.heron.api.spout.SpoutOutputCollector)6 TupleWindow (com.twitter.heron.api.windowing.TupleWindow)6 KeyValue (com.twitter.heron.streamlet.KeyValue)6 LinkedList (java.util.LinkedList)6 Config (com.twitter.heron.api.Config)5 HeronTopology (com.twitter.heron.api.HeronTopology)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)4 TupleWindowImpl (com.twitter.heron.api.windowing.TupleWindowImpl)4 TupleImpl (com.twitter.heron.common.utils.tuple.TupleImpl)4 HashSet (java.util.HashSet)4