use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class CoordinatedBolt method checkFinishId.
private boolean checkFinishId(Tuple tup, TupleType type) {
_collector.flush();
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();
_collector.flush();
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;
} finally {
_collector.flush();
}
}
return failed;
}
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);
}
}
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);
}
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());
}
}
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);
}
Aggregations