Search in sources :

Example 11 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class JoinResult method execute.

public void execute(Tuple tuple) {
    Object requestId = tuple.getValue(0);
    if (tuple.getSourceComponent().equals(returnComponent)) {
        returns.put(requestId, tuple);
    } else {
        results.put(requestId, tuple);
    }
    if (returns.containsKey(requestId) && results.containsKey(requestId)) {
        Tuple result = results.remove(requestId);
        Tuple returner = returns.remove(requestId);
        LOG.debug(result.getValue(1).toString());
        List<Tuple> anchors = new ArrayList<Tuple>();
        anchors.add(result);
        anchors.add(returner);
        _collector.emit(anchors, new Values("" + result.getValue(1), returner.getValue(1)));
        _collector.ack(result);
        _collector.ack(returner);
    }
}
Also used : ArrayList(java.util.ArrayList) Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Example 12 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class SlidingWindowTestSumBolt 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.debug("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));
    LOG.info("#sum = " + sum);
}
Also used : Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Example 13 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class ShellBolt method handleEmit.

private void handleEmit(ShellMsg shellMsg) throws InterruptedException {
    List<Tuple> anchors = new ArrayList<Tuple>();
    List<String> recvAnchors = shellMsg.getAnchors();
    if (recvAnchors != null) {
        for (String anchor : recvAnchors) {
            Tuple t = _inputs.get(anchor);
            if (t == null) {
                throw new RuntimeException("Anchored onto " + anchor + " after ack/fail");
            }
            anchors.add(t);
        }
    }
    if (shellMsg.getTask() == 0) {
        _collector.emit(shellMsg.getStream(), anchors, shellMsg.getTuple(), new ShellEmitCb(shellMsg));
    } else {
        _collector.emitDirect((int) shellMsg.getTask(), shellMsg.getStream(), anchors, shellMsg.getTuple());
    }
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Example 14 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class ShellBolt method handleAck.

private void handleAck(Object id) {
    Tuple acked = _inputs.remove(id);
    if (acked == null) {
        throw new RuntimeException("Acked a non-existent or already acked/failed id: " + id);
    }
    _collector.ack(acked);
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Example 15 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class StatefulBoltExecutor method fail.

private void fail(List<Tuple> tuples) {
    if (!tuples.isEmpty()) {
        LOG.debug("Failing {} tuples", tuples.size());
        for (Tuple tuple : tuples) {
            collector.fail(tuple);
        }
        tuples.clear();
    }
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Aggregations

Tuple (backtype.storm.tuple.Tuple)49 Values (backtype.storm.tuple.Values)11 ArrayList (java.util.ArrayList)10 MessageId (backtype.storm.tuple.MessageId)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Message (com.yahoo.pulsar.client.api.Message)4 TupleImpl (backtype.storm.tuple.TupleImpl)3 TupleImplExt (backtype.storm.tuple.TupleImplExt)3 Pair (com.alibaba.jstorm.utils.Pair)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GlobalStreamId (backtype.storm.generated.GlobalStreamId)2 FailedException (backtype.storm.topology.FailedException)2 TupleExt (backtype.storm.tuple.TupleExt)2 TimerTrigger (com.alibaba.jstorm.daemon.worker.timer.TimerTrigger)2 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)2 RotatingMap (com.alibaba.jstorm.utils.RotatingMap)2 Pair (com.alipay.dw.jstorm.example.sequence.bean.Pair)2 TradeCustomer (com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)2