Search in sources :

Example 11 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values)

Example 12 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values)

Example 13 with Values

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));
}
Also used : Random(java.util.Random) Values(org.apache.storm.tuple.Values)

Example 14 with Values

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);
}
Also used : COMMIT(org.apache.storm.spout.CheckPointState.Action.COMMIT) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple)

Example 15 with Values

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));
}
Also used : Values(org.apache.storm.tuple.Values) CombinerValueUpdater(org.apache.storm.trident.state.CombinerValueUpdater)

Aggregations

Values (org.apache.storm.tuple.Values)206 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)42 Fields (org.apache.storm.tuple.Fields)40 HashMap (java.util.HashMap)39 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 TridentTopology (org.apache.storm.trident.TridentTopology)21 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)14 Stream (org.apache.storm.trident.Stream)12 TupleImpl (org.apache.storm.tuple.TupleImpl)12 List (java.util.List)11 TestUtils (org.apache.storm.sql.TestUtils)11 TridentState (org.apache.storm.trident.TridentState)11 Tuple (org.apache.storm.tuple.Tuple)11 JSONObject (org.json.simple.JSONObject)10 Map (java.util.Map)9 Config (org.apache.storm.Config)9 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)9 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)8 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)8