use of com.twitter.heron.api.tuple.Values in project streaming-samples by ashvina.
the class PartialRanker method execute.
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
restriction.execute();
String trend = tuple.getStringByField(FIELD_TREND);
Long count = tuple.getLongByField(FIELD_COUNT);
RankableObjectWithFields rankable = new RankableObjectWithFields(trend, count, "");
rankings.updateWith(rankable);
if (System.currentTimeMillis() - previousEmitTime > emitRate.toMillis()) {
collector.emit(new Values(rankings.copy()));
previousEmitTime = System.currentTimeMillis();
}
}
use of com.twitter.heron.api.tuple.Values in project streaming-samples by ashvina.
the class TweetSpout method nextTuple.
@Override
public void nextTuple() {
TweetsGenerator.Tweet tweet = tweetsGenerator.nextTweet();
while (tweet.getHashtags().isEmpty() && tweet.getMentions().isEmpty()) {
tweet = tweetsGenerator.nextTweet();
}
String text = tweet.getText();
tweet.getHashtags().forEach(tag -> {
collector.emit(new Values(tag, text));
restriction.execute();
});
tweet.getMentions().forEach(tag -> {
collector.emit(new Values(tag, text));
restriction.execute();
});
}
use of com.twitter.heron.api.tuple.Values in project heron by twitter.
the class IntegrationTestBolt method execute.
@Override
public void execute(Tuple tuple) {
tuplesReceived++;
String streamID = tuple.getSourceStreamId();
LOG.info("Received a tuple: " + tuple + " ; from: " + streamID);
if (streamID.equals(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID)) {
terminalsToReceive--;
if (terminalsToReceive == 0) {
// invoke the finishBatch() callback if necessary
if (IBatchBolt.class.isInstance(delegateBolt)) {
LOG.fine("Invoke bolt to do finishBatch!");
((IBatchBolt) delegateBolt).finishBatch();
}
LOG.info("Received the last terminal, populating the terminals to downstream");
collector.emit(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID, tuple, new Values(Constants.INTEGRATION_TEST_TERMINAL));
} else {
LOG.info(String.format("Received a terminal, need to receive %s more", terminalsToReceive));
}
} else {
currentTupleProcessing = tuple;
delegateBolt.execute(tuple);
// We ack only the tuples in user's logic
collector.ack(tuple);
}
}
use of com.twitter.heron.api.tuple.Values in project heron by twitter.
the class ABSpout method nextTuple.
@Override
public void nextTuple() {
String word = TO_SEND[emitted % TO_SEND.length];
if (appendSequenceId) {
word = word + "_" + emitted;
}
collector.emit(new Values(word));
emitted++;
}
use of com.twitter.heron.api.tuple.Values in project heron by twitter.
the class PausedLocalFileSpout method nextTuple.
// each nextTuple will either read the current line as null, and not emit anything
// or emit one line from the text file
// We do not explicitly close buffered reader. This is so the spout will read any new data
// appended to the file. On spout close, buffered reader will close automatically
@Override
public void nextTuple() {
if (br == null) {
return;
}
try {
String currentLine;
// more content, and do not emit anything if data is null
if ((currentLine = br.readLine()) != null) {
LOG.info("Emitting tuple from input data file: " + currentLine);
collector.emit(new Values(currentLine), "MESSAGE_ID");
}
} 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);
}
}
Aggregations