use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class SingleJoinBolt method execute.
@Override
public void execute(Tuple tuple) {
List<Object> id = tuple.select(_idFields);
GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
if (!_pending.containsKey(id)) {
_pending.put(id, new HashMap<GlobalStreamId, Tuple>());
}
Map<GlobalStreamId, Tuple> parts = _pending.get(id);
if (parts.containsKey(streamId))
throw new RuntimeException("Received same side of single join twice");
parts.put(streamId, tuple);
if (parts.size() == _numSources) {
_pending.remove(id);
List<Object> joinResult = new ArrayList<Object>();
for (String outField : _outFields) {
GlobalStreamId loc = _fieldLocations.get(outField);
joinResult.add(parts.get(loc).getValueByField(outField));
}
_collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
for (Tuple part : parts.values()) {
_collector.ack(part);
}
SingleJoinTest.receiveCounter.incrementAndGet();
}
}
use of backtype.storm.tuple.Tuple in project heron by twitter.
the class OutputCollectorImpl method emitDirect.
@Override
public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
if (anchors != null) {
ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
for (Tuple t : anchors) {
TupleImpl i = (TupleImpl) t;
l.add(i.getDelegate());
}
delegate.emitDirect(taskId, streamId, l, tuple);
} else {
delegate.emitDirect(taskId, streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
}
}
use of backtype.storm.tuple.Tuple in project heron by twitter.
the class OutputCollectorImpl method emit.
@Override
public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
if (anchors != null) {
ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
for (Tuple t : anchors) {
TupleImpl i = (TupleImpl) t;
l.add(i.getDelegate());
}
return delegate.emit(streamId, l, tuple);
} else {
return delegate.emit(streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
}
}
use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class MergeRecord method execute.
@Override
public void execute(Tuple input) {
tpsCounter.count();
Long tupleId = input.getLong(0);
Pair pair = (Pair) input.getValue(1);
Pair trade = null;
Pair customer = null;
Tuple tradeTuple = null;
Tuple customerTuple = null;
if (input.getSourceComponent().equals(SequenceTopologyDef.CUSTOMER_BOLT_NAME)) {
customer = pair;
customerTuple = input;
tradeTuple = tradeMap.remove(tupleId);
if (tradeTuple == null) {
customerMap.put(tupleId, input);
return;
}
trade = (Pair) tradeTuple.getValue(1);
} else if (input.getSourceComponent().equals(SequenceTopologyDef.TRADE_BOLT_NAME)) {
trade = pair;
tradeTuple = input;
customerTuple = customerMap.remove(tupleId);
if (customerTuple == null) {
tradeMap.put(tupleId, input);
return;
}
customer = (Pair) customerTuple.getValue(1);
} else {
LOG.info("Unknow source component: " + input.getSourceComponent());
collector.fail(input);
return;
}
tradeSum.addAndGet(trade.getValue());
customerSum.addAndGet(customer.getValue());
collector.ack(tradeTuple);
collector.ack(customerTuple);
TradeCustomer tradeCustomer = new TradeCustomer();
tradeCustomer.setTrade(trade);
tradeCustomer.setCustomer(customer);
collector.emit(new Values(tupleId, tradeCustomer));
}
use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
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.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));
}
Aggregations