use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class ReduceByKeyAndWindowOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
Map<K, V> reduceMap = new HashMap<>();
Map<K, Integer> windowCountMap = new HashMap<>();
for (Tuple tuple : inputWindow.get()) {
R tup = (R) tuple.getValue(0);
addMap(reduceMap, windowCountMap, tup);
}
long startWindow;
long endWindow;
if (inputWindow.getStartTimestamp() == null) {
startWindow = 0;
} else {
startWindow = inputWindow.getStartTimestamp();
}
if (inputWindow.getEndTimestamp() == null) {
endWindow = 0;
} else {
endWindow = inputWindow.getEndTimestamp();
}
for (K key : reduceMap.keySet()) {
Window window = new Window(startWindow, endWindow, windowCountMap.get(key));
KeyedWindow<K> keyedWindow = new KeyedWindow<>(key, window);
collector.emit(new Values(new KeyValue<>(keyedWindow, reduceMap.get(key))));
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class TestSpout method nextTuple.
@Override
public void nextTuple() {
// It will emit A, B, A, B, A, B, A, B, A, B
if (emitted < EMIT_COUNT) {
String word = toSend[emitted % toSend.length];
emit(outputCollector, new Values(word), MESSAGE_ID, emitted++);
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class TestBolt method execute.
@Override
public void execute(Tuple tuple) {
AtomicInteger ackCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.ACK_COUNT);
AtomicInteger failCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.FAIL_COUNT);
AtomicInteger tupleExecutedCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_COUNT);
CountDownLatch tupleExecutedLatch = (CountDownLatch) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_LATCH);
StringBuilder receivedStrings = (StringBuilder) SingletonRegistry.INSTANCE.getSingleton(Constants.RECEIVED_STRING_LIST);
if (receivedStrings != null) {
receivedStrings.append(tuple.getString(0));
}
if (tupleExecutedCount != null) {
tupleExecutedCount.getAndIncrement();
}
if ((tupleExecuted & 1) == 0) {
outputCollector.ack(tuple);
if (ackCount != null) {
ackCount.getAndIncrement();
}
} else {
outputCollector.fail(tuple);
if (failCount != null) {
failCount.getAndIncrement();
}
}
tupleExecuted++;
outputCollector.emit(new Values(tuple.getString(0)));
if (tupleExecutedLatch != null) {
tupleExecutedLatch.countDown();
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class EmitDirectRoundRobinBolt method execute.
@Override
public void execute(Tuple tuple) {
String word = toSend[emitted % toSend.length];
outputCollector.emitDirect(emitted, new Values(word));
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class FlatMapOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
Iterable<? extends T> result = flatMapFn.apply(obj);
for (T o : result) {
collector.emit(new Values(o));
}
collector.ack(tuple);
}
Aggregations