Search in sources :

Example 1 with TupleImpl

use of org.apache.storm.tuple.TupleImpl in project storm by apache.

the class AvroGenericRecordBoltTest method generateTestTuple.

private static Tuple generateTestTuple(GenericRecord record) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("record");
        }
    };
    return new TupleImpl(topologyContext, new Values(record), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 2 with TupleImpl

use of org.apache.storm.tuple.TupleImpl in project storm by apache.

the class TestHdfsBolt method generateTestTuple.

private Tuple generateTestTuple(Object id, Object msg, Object city, Object state) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("id", "msg", "city", "state");
        }
    };
    return new TupleImpl(topologyContext, new Values(id, msg, city, state), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 3 with TupleImpl

use of org.apache.storm.tuple.TupleImpl in project storm by apache.

the class TestSequenceFileBolt method generateTestTuple.

private Tuple generateTestTuple(Long key, String value) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("key", "value");
        }
    };
    return new TupleImpl(topologyContext, new Values(key, value), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 4 with TupleImpl

use of org.apache.storm.tuple.TupleImpl in project storm by apache.

the class Executor method setupTicks.

protected void setupTicks(boolean isSpout) {
    final Integer tickTimeSecs = Utils.getInt(stormConf.get(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS), null);
    boolean enableMessageTimeout = (Boolean) stormConf.get(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS);
    if (tickTimeSecs != null) {
        if (Utils.isSystemId(componentId) || (!enableMessageTimeout && isSpout)) {
            LOG.info("Timeouts disabled for executor " + componentId + ":" + executorId);
        } else {
            StormTimer timerTask = workerData.getUserTimer();
            timerTask.scheduleRecurring(tickTimeSecs, tickTimeSecs, new Runnable() {

                @Override
                public void run() {
                    TupleImpl tuple = new TupleImpl(workerTopologyContext, new Values(tickTimeSecs), (int) Constants.SYSTEM_TASK_ID, Constants.SYSTEM_TICK_STREAM_ID);
                    List<AddressedTuple> tickTuple = Lists.newArrayList(new AddressedTuple(AddressedTuple.BROADCAST_DEST, tuple));
                    receiveQueue.publish(tickTuple);
                }
            });
        }
    }
}
Also used : StormTimer(org.apache.storm.StormTimer) Values(org.apache.storm.tuple.Values) List(java.util.List) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TupleImpl(org.apache.storm.tuple.TupleImpl) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Example 5 with TupleImpl

use of org.apache.storm.tuple.TupleImpl in project storm by apache.

the class Executor method onEvent.

@SuppressWarnings("unchecked")
@Override
public void onEvent(Object event, long seq, boolean endOfBatch) throws Exception {
    ArrayList<AddressedTuple> addressedTuples = (ArrayList<AddressedTuple>) event;
    for (AddressedTuple addressedTuple : addressedTuples) {
        TupleImpl tuple = (TupleImpl) addressedTuple.getTuple();
        int taskId = addressedTuple.getDest();
        if (isDebug) {
            LOG.info("Processing received message FOR {} TUPLE: {}", taskId, tuple);
        }
        if (taskId != AddressedTuple.BROADCAST_DEST) {
            tupleActionFn(taskId, tuple);
        } else {
            for (Integer t : taskIds) {
                tupleActionFn(t, tuple);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TupleImpl(org.apache.storm.tuple.TupleImpl) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Aggregations

TupleImpl (org.apache.storm.tuple.TupleImpl)23 Values (org.apache.storm.tuple.Values)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 Fields (org.apache.storm.tuple.Fields)8 Config (org.apache.storm.Config)7 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)7 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)7 Tuple (org.apache.storm.tuple.Tuple)5 AddressedTuple (org.apache.storm.tuple.AddressedTuple)4 MessageId (org.apache.storm.tuple.MessageId)3 List (java.util.List)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 StormTimer (org.apache.storm.StormTimer)2 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TupleInfo (org.apache.storm.executor.TupleInfo)1 BoltAckInfo (org.apache.storm.hooks.info.BoltAckInfo)1