Search in sources :

Example 1 with AddressedTuple

use of org.apache.storm.tuple.AddressedTuple 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 2 with AddressedTuple

use of org.apache.storm.tuple.AddressedTuple 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)

Example 3 with AddressedTuple

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

the class ExecutorShutdown method credentialsChanged.

@Override
public void credentialsChanged(Credentials credentials) {
    TupleImpl tuple = new TupleImpl(executor.getWorkerTopologyContext(), new Values(credentials), (int) Constants.SYSTEM_TASK_ID, Constants.CREDENTIALS_CHANGED_STREAM_ID);
    List<AddressedTuple> addressedTuple = Lists.newArrayList(new AddressedTuple(AddressedTuple.BROADCAST_DEST, tuple));
    executor.getReceiveQueue().publish(addressedTuple);
}
Also used : Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Example 4 with AddressedTuple

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

the class ExecutorTransfer method transfer.

public void transfer(int task, Tuple tuple) {
    AddressedTuple val = new AddressedTuple(task, tuple);
    if (isDebug) {
        LOG.info("TRANSFERRING tuple {}", val);
    }
    batchTransferQueue.publish(val);
}
Also used : AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Example 5 with AddressedTuple

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

the class WorkerState method transfer.

public void transfer(KryoTupleSerializer serializer, List<AddressedTuple> tupleBatch) {
    if (trySerializeLocal) {
        assertCanSerialize(serializer, tupleBatch);
    }
    List<AddressedTuple> local = new ArrayList<>();
    Map<Integer, List<TaskMessage>> remoteMap = new HashMap<>();
    for (AddressedTuple addressedTuple : tupleBatch) {
        int destTask = addressedTuple.getDest();
        if (taskIds.contains(destTask)) {
            // Local task
            local.add(addressedTuple);
        } else {
            // Using java objects directly to avoid performance issues in java code
            if (!remoteMap.containsKey(destTask)) {
                remoteMap.put(destTask, new ArrayList<>());
            }
            remoteMap.get(destTask).add(new TaskMessage(destTask, serializer.serialize(addressedTuple.getTuple())));
        }
    }
    if (!local.isEmpty()) {
        transferLocal(local);
    }
    if (!remoteMap.isEmpty()) {
        transferQueue.publish(remoteMap);
    }
}
Also used : AddressedTuple(org.apache.storm.tuple.AddressedTuple) TaskMessage(org.apache.storm.messaging.TaskMessage)

Aggregations

AddressedTuple (org.apache.storm.tuple.AddressedTuple)8 ArrayList (java.util.ArrayList)4 TupleImpl (org.apache.storm.tuple.TupleImpl)4 Values (org.apache.storm.tuple.Values)3 List (java.util.List)2 StormTimer (org.apache.storm.StormTimer)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 TaskMessage (org.apache.storm.messaging.TaskMessage)1 KryoTupleDeserializer (org.apache.storm.serialization.KryoTupleDeserializer)1 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)1