Search in sources :

Example 1 with Tuple

use of backtype.storm.tuple.Tuple in project storm by nathanmarz.

the class ShellBolt method handleEmit.

private void handleEmit(Map action) throws InterruptedException {
    String stream = (String) action.get("stream");
    if (stream == null)
        stream = Utils.DEFAULT_STREAM_ID;
    Long task = (Long) action.get("task");
    List<Object> tuple = (List) action.get("tuple");
    List<Tuple> anchors = new ArrayList<Tuple>();
    Object anchorObj = action.get("anchors");
    if (anchorObj != null) {
        if (anchorObj instanceof String) {
            anchorObj = Arrays.asList(anchorObj);
        }
        for (Object o : (List) anchorObj) {
            Tuple t = _inputs.get((String) o);
            if (t == null) {
                throw new RuntimeException("Anchored onto " + o + " after ack/fail");
            }
            anchors.add(t);
        }
    }
    if (task == null) {
        List<Integer> outtasks = _collector.emit(stream, anchors, tuple);
        Object need_task_ids = action.get("need_task_ids");
        if (need_task_ids == null || ((Boolean) need_task_ids).booleanValue()) {
            _pendingWrites.put(outtasks);
        }
    } else {
        _collector.emitDirect((int) task.longValue(), stream, anchors, tuple);
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject) Tuple(backtype.storm.tuple.Tuple)

Example 2 with Tuple

use of backtype.storm.tuple.Tuple in project storm by nathanmarz.

the class ShellBolt method handleFail.

private void handleFail(Map action) {
    String id = (String) action.get("id");
    Tuple failed = _inputs.remove(id);
    if (failed == null) {
        throw new RuntimeException("Failed a non-existent or already acked/failed id: " + id);
    }
    _collector.fail(failed);
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Example 3 with Tuple

use of backtype.storm.tuple.Tuple in project storm by nathanmarz.

the class CoordinatedBolt method checkFinishId.

private boolean checkFinishId(Tuple tup, TupleType type) {
    Object id = tup.getValue(0);
    boolean failed = false;
    synchronized (_tracked) {
        TrackingInfo track = _tracked.get(id);
        try {
            if (track != null) {
                boolean delayed = false;
                if (_idStreamSpec == null && type == TupleType.COORD || _idStreamSpec != null && type == TupleType.ID) {
                    track.ackTuples.add(tup);
                    delayed = true;
                }
                if (track.failed) {
                    failed = true;
                    for (Tuple t : track.ackTuples) {
                        _collector.fail(t);
                    }
                    _tracked.remove(id);
                } else if (track.receivedId && (_sourceArgs.isEmpty() || track.reportCount == _numSourceReports && track.expectedTupleCount == track.receivedTuples)) {
                    if (_delegate instanceof FinishedCallback) {
                        ((FinishedCallback) _delegate).finishedId(id);
                    }
                    if (!(_sourceArgs.isEmpty() || type != TupleType.REGULAR)) {
                        throw new IllegalStateException("Coordination condition met on a non-coordinating tuple. Should be impossible");
                    }
                    Iterator<Integer> outTasks = _countOutTasks.iterator();
                    while (outTasks.hasNext()) {
                        int task = outTasks.next();
                        int numTuples = get(track.taskEmittedTuples, task, 0);
                        _collector.emitDirect(task, Constants.COORDINATED_STREAM_ID, tup, new Values(id, numTuples));
                    }
                    for (Tuple t : track.ackTuples) {
                        _collector.ack(t);
                    }
                    track.finished = true;
                    _tracked.remove(id);
                }
                if (!delayed && type != TupleType.REGULAR) {
                    if (track.failed) {
                        _collector.fail(tup);
                    } else {
                        _collector.ack(tup);
                    }
                }
            } else {
                if (type != TupleType.REGULAR)
                    _collector.fail(tup);
            }
        } catch (FailedException e) {
            LOG.error("Failed to finish batch", e);
            for (Tuple t : track.ackTuples) {
                _collector.fail(t);
            }
            _tracked.remove(id);
            failed = true;
        }
    }
    return failed;
}
Also used : FailedException(backtype.storm.topology.FailedException) Iterator(java.util.Iterator) Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Example 4 with Tuple

use of backtype.storm.tuple.Tuple in project storm by nathanmarz.

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 5 with Tuple

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

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) {
            windowedOutputCollector.setContext(tuples);
            bolt.execute(new TupleWindowImpl(tuples, newTuples, expiredTuples));
        }
    };
}
Also used : TupleWindowImpl(backtype.storm.windowing.TupleWindowImpl) WindowLifecycleListener(backtype.storm.windowing.WindowLifecycleListener) List(java.util.List) 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