use of org.apache.heron.api.tuple.Values in project heron by twitter.
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 org.apache.heron.api.tuple.Values in project heron by twitter.
the class LocalFileSpout method nextTuple.
// We do not explicitly close the buffered reader, even on EoF. This is in case more content is
// added to file, we will read that content as well
@Override
public void nextTuple() {
if (br == null) {
return;
}
try {
String currentLine;
if ((currentLine = br.readLine()) != null) {
collector.emit(new Values(currentLine));
} else {
br.close();
br = null;
}
} catch (IOException e) {
// Clean stuff if any exceptions
try {
// Close the outmost is enough
if (br != null) {
br.close();
}
} catch (IOException e1) {
throw new RuntimeException("Unable to close stream reader", e1);
}
throw new RuntimeException("Unable to emit tuples normally", e);
}
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class HdfsStringSpout method nextTuple.
@Override
public void nextTuple() {
if (br == null) {
return;
}
try {
String line = "";
if ((line = br.readLine()) != null) {
collector.emit(new Values(line));
} else {
br.close();
br = null;
}
} catch (IOException e) {
// Clean stuff if any exceptions
try {
// Close the outmost is enough
br.close();
} catch (IOException e1) {
throw new RuntimeException("Unable to close stream reader", e1);
}
throw new RuntimeException("Unable to emit tuples normally", e);
}
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class TestBasicBolt method execute.
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
tupleExecuted++;
collector.emit(new Values(input.getString(0)));
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class GeneralReduceByKeyAndWindowOperatorTest method getTupleWindow.
private TupleWindow getTupleWindow(int nkeys, int count) {
TopologyAPI.StreamId componentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("sourceComponent").setId("default").build();
List<Tuple> tuples = new LinkedList<>();
for (int i = 0; i < nkeys; i++) {
for (int j = 0; j < count; ++j) {
Tuple tuple = getTuple(componentStreamId, new Fields("a"), new Values(new KeyValue<>(String.valueOf(i), j)));
tuples.add(tuple);
}
}
TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
return tupleWindow;
}
Aggregations