use of org.apache.storm.tuple.Values in project storm by apache.
the class TestEventOrderCheckBolt method execute.
public void execute(Tuple input) {
Integer sourceId = input.getInteger(0);
Long eventId = input.getLong(1);
Long recentEvent = recentEventId.get(sourceId);
if (null != recentEvent && eventId <= recentEvent) {
String error = "Error: event id is not in strict order! event source Id: " + sourceId + ", last event Id: " + recentEvent + ", current event Id: " + eventId;
_collector.emit(input, new Values(error));
}
recentEventId.put(sourceId, eventId);
_collector.ack(input);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestGlobalCount method execute.
public void execute(Tuple input) {
_count++;
_collector.emit(input, new Values(_count));
_collector.ack(input);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestWordSpout method nextTuple.
public void nextTuple() {
Utils.sleep(100);
final String[] words = new String[] { "nathan", "mike", "jackson", "golda", "bertels" };
final Random rand = new Random();
final String word = words[rand.nextInt(words.length)];
_collector.emit(new Values(word));
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class StatefulBoltExecutor method handleCheckpoint.
@Override
protected void handleCheckpoint(Tuple checkpointTuple, Action action, long txid) {
LOG.debug("handleCheckPoint with tuple {}, action {}, txid {}", checkpointTuple, action, txid);
if (action == PREPARE) {
if (boltInitialized) {
bolt.prePrepare(txid);
state.prepareCommit(txid);
preparedTuples.addAll(collector.ackedTuples());
} else {
/*
* May be the task restarted in the middle and the state needs be initialized.
* Fail fast and trigger recovery.
*/
LOG.debug("Failing checkpointTuple, PREPARE received when bolt state is not initialized.");
collector.fail(checkpointTuple);
return;
}
} else if (action == COMMIT) {
bolt.preCommit(txid);
state.commit(txid);
ack(preparedTuples);
} else if (action == ROLLBACK) {
bolt.preRollback();
state.rollback();
fail(preparedTuples);
fail(collector.ackedTuples());
} else if (action == INITSTATE) {
if (!boltInitialized) {
bolt.initState((T) state);
boltInitialized = true;
LOG.debug("{} pending tuples to process", pendingTuples.size());
for (Tuple tuple : pendingTuples) {
doExecute(tuple);
}
pendingTuples.clear();
} else {
LOG.debug("Bolt state is already initialized, ignoring tuple {}, action {}, txid {}", checkpointTuple, action, txid);
}
}
collector.emit(CheckpointSpout.CHECKPOINT_STREAM_ID, checkpointTuple, new Values(txid, action));
collector.delegate.ack(checkpointTuple);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class CombinerAggStateUpdater method updateState.
@Override
public void updateState(Snapshottable state, List<TridentTuple> tuples, TridentCollector collector) {
if (tuples.size() != 1) {
throw new IllegalArgumentException("Combiner state updater should receive a single tuple. Received: " + tuples.toString());
}
Object newVal = state.update(new CombinerValueUpdater(_agg, tuples.get(0).getValue(0)));
collector.emit(new Values(newVal));
}
Aggregations