Search in sources :

Example 6 with Values

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

the class MapOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
    R obj = (R) tuple.getValue(0);
    T result = mapFn.apply(obj);
    collector.emit(new Values(result));
    collector.ack(tuple);
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 7 with Values

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

the class IntegrationTestBolt method execute.

@Override
public void execute(Tuple tuple) {
    String streamID = tuple.getSourceStreamId();
    LOG.info("Received a tuple: " + tuple + " ; from: " + streamID);
    if (streamID.equals(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID)) {
        terminalsToReceive--;
        if (terminalsToReceive == 0) {
            // invoke the finishBatch() callback if necessary
            if (IBatchBolt.class.isInstance(delegateBolt)) {
                LOG.fine("Invoke bolt to do finishBatch!");
                ((IBatchBolt) delegateBolt).finishBatch();
            }
            LOG.info("Received the last terminal, populating the terminals to downstream");
            collector.emit(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID, tuple, new Values(Constants.INTEGRATION_TEST_TERMINAL));
        } else {
            LOG.info(String.format("Received a terminal, need to receive %s more", terminalsToReceive));
        }
    } else {
        tuplesReceived++;
        currentTupleProcessing = tuple;
        delegateBolt.execute(tuple);
        // We ack only the tuples in user's logic
        if (this.ackAuto) {
            collector.ack(tuple);
        }
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 8 with Values

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

the class PausedLocalFileSpout method nextTuple.

// each nextTuple will either read the current line as null, and not emit anything
// or emit one line from the text file
// We do not explicitly close buffered reader. This is so the spout will read any new data
// appended to the file. On spout close, buffered reader will close automatically
@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String currentLine;
        // more content, and do not emit anything if data is null
        if ((currentLine = br.readLine()) != null) {
            LOG.info("Emitting tuple from input data file: " + currentLine);
            collector.emit(new Values(currentLine), "MESSAGE_ID");
        }
    } catch (IOException e) {
        // Clean stuff if any exceptions
        try {
            // Close the outmost is enough
            if (br != null) {
                br.close();
            }
        } catch (IOException e1) {
            throw new RuntimeException("Unable to close stream reader", e1);
        }
        throw new RuntimeException("Unable to emit tuples normally", e);
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values) IOException(java.io.IOException)

Example 9 with Values

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

the class SlidingWindowSumBolt method execute.

@Override
public void execute(TupleWindow inputWindow) {
    /*
             * The inputWindow gives a view of
             * (a) all the events in the window
             * (b) events that expired since last activation of the window
             * (c) events that newly arrived since last activation of the window
             */
    List<Tuple> tuplesInWindow = inputWindow.get();
    List<Tuple> newTuples = inputWindow.getNew();
    List<Tuple> expiredTuples = inputWindow.getExpired();
    LOG.fine("Events in current window: " + tuplesInWindow.size());
    /*
             * Instead of iterating over all the tuples in the window to compute
             * the sum, the values for the new events are added and old events are
             * subtracted. Similar optimizations might be possible in other
             * windowing computations.
             */
    for (Tuple tuple : newTuples) {
        sum += (int) tuple.getValue(0);
    }
    for (Tuple tuple : expiredTuples) {
        sum -= (int) tuple.getValue(0);
    }
    collector.emit(new Values(sum));
}
Also used : Values(com.twitter.heron.api.tuple.Values) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 10 with Values

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

the class RandomIntegerSpout method nextTuple.

@Override
public void nextTuple() {
    Utils.sleep(100);
    collector.emit(new Values(rand.nextInt(1000), System.currentTimeMillis() - (24 * 60 * 60 * 1000), ++msgId), msgId);
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Aggregations

Values (com.twitter.heron.api.tuple.Values)34 Tuple (com.twitter.heron.api.tuple.Tuple)7 TupleWindow (com.twitter.heron.api.windowing.TupleWindow)6 IOException (java.io.IOException)6 Fields (com.twitter.heron.api.tuple.Fields)5 KeyValue (com.twitter.heron.streamlet.KeyValue)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)3 TupleWindowImpl (com.twitter.heron.api.windowing.TupleWindowImpl)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 KeyedWindow (com.twitter.heron.streamlet.KeyedWindow)2 Window (com.twitter.heron.streamlet.Window)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 TweetsGenerator (com.github.ashvina.common.TweetsGenerator)1 TopologyContext (com.twitter.heron.api.topology.TopologyContext)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RankableObjectWithFields (org.apache.storm.starter.tools.RankableObjectWithFields)1