Search in sources :

Example 1 with MessageId

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

use of org.apache.storm.tuple.MessageId in project flink by apache.

the class StormTupleTest method testGetMessageId.

@Test
public void testGetMessageId() {
    MessageId messageId = MessageId.makeUnanchored();
    StormTuple<?> stormTuple = new StormTuple<>(null, null, -1, null, null, messageId);
    Assert.assertSame(messageId, stormTuple.getMessageId());
}
Also used : MessageId(org.apache.storm.tuple.MessageId) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Example 3 with MessageId

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

the class KryoTupleDeserializer method deserialize.

public Tuple deserialize(byte[] ser) {
    try {
        _kryoInput.setBuffer(ser);
        int taskId = _kryoInput.readInt(true);
        int streamId = _kryoInput.readInt(true);
        String componentName = _context.getComponentId(taskId);
        String streamName = _ids.getStreamName(componentName, streamId);
        MessageId id = MessageId.deserialize(_kryoInput);
        List<Object> values = _kryo.deserializeFrom(_kryoInput);
        return new TupleImpl(_context, values, taskId, streamName, id);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) TupleImpl(org.apache.storm.tuple.TupleImpl) MessageId(org.apache.storm.tuple.MessageId)

Example 4 with MessageId

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

the class BoltOutputCollectorImpl method boltEmit.

private List<Integer> boltEmit(String streamId, Collection<Tuple> anchors, List<Object> values, Integer targetTaskId) {
    List<Integer> outTasks;
    if (targetTaskId != null) {
        outTasks = taskData.getOutgoingTasks(targetTaskId, streamId, values);
    } else {
        outTasks = taskData.getOutgoingTasks(streamId, values);
    }
    for (Integer t : outTasks) {
        Map<Long, Long> anchorsToIds = new HashMap<>();
        if (anchors != null) {
            for (Tuple a : anchors) {
                Set<Long> rootIds = a.getMessageId().getAnchorsToIds().keySet();
                if (rootIds.size() > 0) {
                    long edgeId = MessageId.generateId(random);
                    ((TupleImpl) a).updateAckVal(edgeId);
                    for (Long root_id : rootIds) {
                        putXor(anchorsToIds, root_id, edgeId);
                    }
                }
            }
        }
        MessageId msgId = MessageId.makeId(anchorsToIds);
        TupleImpl tupleExt = new TupleImpl(executor.getWorkerTopologyContext(), values, taskId, streamId, msgId);
        executor.getExecutorTransfer().transfer(t, tupleExt);
    }
    if (isEventLoggers) {
        executor.sendToEventLogger(executor, taskData, values, executor.getComponentId(), null, random);
    }
    return outTasks;
}
Also used : HashMap(java.util.HashMap) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) MessageId(org.apache.storm.tuple.MessageId)

Aggregations

MessageId (org.apache.storm.tuple.MessageId)4 TupleImpl (org.apache.storm.tuple.TupleImpl)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AbstractTest (org.apache.flink.storm.util.AbstractTest)1 TupleInfo (org.apache.storm.executor.TupleInfo)1 Tuple (org.apache.storm.tuple.Tuple)1 Values (org.apache.storm.tuple.Values)1 MutableLong (org.apache.storm.utils.MutableLong)1 Test (org.junit.Test)1