Search in sources :

Example 1 with TupleInfo

use of org.apache.storm.executor.TupleInfo in project storm by apache.

the class SpoutOutputCollectorImpl method sendSpoutMsg.

private List<Integer> sendSpoutMsg(String stream, List<Object> values, Object messageId, Integer outTaskId) {
    emittedCount.increment();
    List<Integer> outTasks;
    if (outTaskId != null) {
        outTasks = taskData.getOutgoingTasks(outTaskId, stream, values);
    } else {
        outTasks = taskData.getOutgoingTasks(stream, values);
    }
    List<Long> ackSeq = new ArrayList<>();
    boolean needAck = (messageId != null) && hasAckers;
    long rootId = MessageId.generateId(random);
    for (Integer t : outTasks) {
        MessageId msgId;
        if (needAck) {
            long as = MessageId.generateId(random);
            msgId = MessageId.makeRootId(rootId, as);
            ackSeq.add(as);
        } else {
            msgId = MessageId.makeUnanchored();
        }
        TupleImpl tuple = new TupleImpl(executor.getWorkerTopologyContext(), values, this.taskId, stream, msgId);
        executor.getExecutorTransfer().transfer(t, tuple);
    }
    if (isEventLoggers) {
        executor.sendToEventLogger(executor, taskData, values, executor.getComponentId(), messageId, random);
    }
    boolean sample = false;
    try {
        sample = executor.getSampler().call();
    } catch (Exception ignored) {
    }
    if (needAck) {
        TupleInfo info = new TupleInfo();
        info.setTaskId(this.taskId);
        info.setStream(stream);
        info.setMessageId(messageId);
        if (isDebug) {
            info.setValues(values);
        }
        if (sample) {
            info.setTimestamp(System.currentTimeMillis());
        }
        pending.put(rootId, info);
        List<Object> ackInitTuple = new Values(rootId, Utils.bitXorVals(ackSeq), this.taskId);
        executor.sendUnanchored(taskData, Acker.ACKER_INIT_STREAM_ID, ackInitTuple, executor.getExecutorTransfer());
    } else if (messageId != null) {
        TupleInfo info = new TupleInfo();
        info.setStream(stream);
        info.setValues(values);
        info.setMessageId(messageId);
        info.setTimestamp(0);
        Long timeDelta = sample ? 0L : null;
        info.setId("0:");
        executor.ackSpoutMsg(executor, taskData, timeDelta, info);
    }
    return outTasks;
}
Also used : TupleInfo(org.apache.storm.executor.TupleInfo) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) MutableLong(org.apache.storm.utils.MutableLong) TupleImpl(org.apache.storm.tuple.TupleImpl) MessageId(org.apache.storm.tuple.MessageId)

Example 2 with TupleInfo

use of org.apache.storm.executor.TupleInfo in project storm by apache.

the class SpoutExecutor method init.

public void init(final Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Opening spout {}:{}", componentId, idToTask.keySet());
    this.idToTask = idToTask;
    this.maxSpoutPending = Utils.getInt(stormConf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING), 0) * idToTask.size();
    this.spouts = new ArrayList<>();
    for (Task task : idToTask.values()) {
        this.spouts.add((ISpout) task.getTaskObject());
    }
    this.pending = new RotatingMap<>(2, new RotatingMap.ExpiredCallback<Long, TupleInfo>() {

        @Override
        public void expire(Long key, TupleInfo tupleInfo) {
            Long timeDelta = null;
            if (tupleInfo.getTimestamp() != 0) {
                timeDelta = Time.deltaMs(tupleInfo.getTimestamp());
            }
            failSpoutMsg(SpoutExecutor.this, idToTask.get(tupleInfo.getTaskId()), timeDelta, tupleInfo, "TIMEOUT");
        }
    });
    this.spoutThrottlingMetrics.registerAll(stormConf, idToTask.values().iterator().next().getUserContext());
    this.outputCollectors = new ArrayList<>();
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        ISpout spoutObject = (ISpout) taskData.getTaskObject();
        SpoutOutputCollectorImpl spoutOutputCollector = new SpoutOutputCollectorImpl(spoutObject, this, taskData, entry.getKey(), emittedCount, hasAckers, rand, hasEventLoggers, isDebug, pending);
        SpoutOutputCollector outputCollector = new SpoutOutputCollector(spoutOutputCollector);
        this.outputCollectors.add(outputCollector);
        taskData.getBuiltInMetrics().registerAll(stormConf, taskData.getUserContext());
        Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
        BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, taskData.getUserContext());
        if (spoutObject instanceof ICredentialsListener) {
            ((ICredentialsListener) spoutObject).setCredentials(credentials);
        }
        spoutObject.open(stormConf, taskData.getUserContext(), outputCollector);
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Opened spout {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) TupleInfo(org.apache.storm.executor.TupleInfo) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) MutableLong(org.apache.storm.utils.MutableLong) RotatingMap(org.apache.storm.utils.RotatingMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ISpout(org.apache.storm.spout.ISpout)

Aggregations

TupleInfo (org.apache.storm.executor.TupleInfo)2 MutableLong (org.apache.storm.utils.MutableLong)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ICredentialsListener (org.apache.storm.ICredentialsListener)1 Task (org.apache.storm.daemon.Task)1 ISpout (org.apache.storm.spout.ISpout)1 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)1 MessageId (org.apache.storm.tuple.MessageId)1 TupleImpl (org.apache.storm.tuple.TupleImpl)1 Values (org.apache.storm.tuple.Values)1 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)1 RotatingMap (org.apache.storm.utils.RotatingMap)1