Search in sources :

Example 11 with MessageId

use of backtype.storm.tuple.MessageId in project jstorm by alibaba.

the class SpoutCollector method sendMsg.

public List<Integer> sendMsg(String out_stream_id, List<Object> values, Object message_id, Integer out_task_id, ICollectorCallback callback) {
    final long startTime = emitTotalTimer.getTime();
    try {
        boolean needAck = (message_id != null) && (ackerNum > 0);
        Long root_id = getRootId(message_id);
        List<Integer> outTasks = null;
        if (out_task_id != null) {
            outTasks = sendTargets.get(out_task_id, out_stream_id, values, null, root_id);
        } else {
            outTasks = sendTargets.get(out_stream_id, values, null, root_id);
        }
        List<Long> ackSeq = new ArrayList<Long>();
        for (Integer t : outTasks) {
            MessageId msgid;
            if (needAck) {
                // Long as = MessageId.generateId();
                Long as = MessageId.generateId(random);
                msgid = MessageId.makeRootId(root_id, as);
                ackSeq.add(as);
            } else {
                msgid = null;
            }
            TupleImplExt tp = new TupleImplExt(topology_context, values, task_id, out_stream_id, msgid);
            tp.setTargetTaskId(t);
            transfer_fn.transfer(tp);
        }
        sendMsgToAck(out_stream_id, values, message_id, root_id, ackSeq, needAck);
        if (callback != null)
            callback.execute(out_stream_id, outTasks, values);
        return outTasks;
    } finally {
        emitTotalTimer.updateTime(startTime);
    }
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) ArrayList(java.util.ArrayList) MessageId(backtype.storm.tuple.MessageId)

Example 12 with MessageId

use of backtype.storm.tuple.MessageId in project jstorm by alibaba.

the class SpoutExecutors method onEvent.

/**
     * Handle acker message
     *
     * @see com.lmax.disruptor.EventHandler#onEvent(java.lang.Object, long, boolean)
     */
@Override
public void onEvent(Object event, long sequence, boolean endOfBatch) throws Exception {
    try {
        if (event == null) {
            return;
        }
        Runnable runnable = null;
        if (event instanceof Tuple) {
            if (((TupleExt) event).isBatchTuple()) {
                List<Object> values = ((Tuple) event).getValues();
                for (Object value : values) {
                    Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
                    TupleImplExt tuple = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) event));
                    processControlEvent();
                    runnable = processTupleEvent(tuple);
                    if (runnable != null) {
                        runnable.run();
                        runnable = null;
                    }
                }
            } else {
                runnable = processTupleEvent((Tuple) event);
            }
        } else if (event instanceof TimerTrigger.TimerEvent) {
            processTimerEvent((TimerTrigger.TimerEvent) event);
            return;
        } else if (event instanceof IAckMsg) {
            runnable = (Runnable) event;
        } else if (event instanceof Runnable) {
            runnable = (Runnable) event;
        } else {
            LOG.warn("Receive one unknow event-" + event.toString() + " " + idStr);
            return;
        }
        if (runnable != null)
            runnable.run();
    } catch (Throwable e) {
        if (!taskStatus.isShutdown()) {
            LOG.info("Unknow excpetion ", e);
            report_error.report(e);
        }
    }
}
Also used : TupleExt(backtype.storm.tuple.TupleExt) TupleImplExt(backtype.storm.tuple.TupleImplExt) List(java.util.List) TimerTrigger(com.alibaba.jstorm.daemon.worker.timer.TimerTrigger) Tuple(backtype.storm.tuple.Tuple) Pair(com.alibaba.jstorm.utils.Pair) MessageId(backtype.storm.tuple.MessageId)

Example 13 with MessageId

use of backtype.storm.tuple.MessageId in project jstorm by alibaba.

the class KryoTupleSerializer method serializeTuple.

/**
     * @@@ in the furture, it will skill serialize 'targetTask' through check some flag
     * @see backtype.storm.serialization.ITupleSerializer#serialize(int, backtype.storm.tuple.Tuple)
     */
private void serializeTuple(Output output, Tuple tuple) {
    try {
        boolean isBatchTuple = false;
        if (tuple instanceof TupleExt) {
            output.writeInt(((TupleExt) tuple).getTargetTaskId());
            output.writeLong(((TupleExt) tuple).getCreationTimeStamp());
            output.writeBoolean(((TupleExt) tuple).isBatchTuple());
            isBatchTuple = ((TupleExt) tuple).isBatchTuple();
        }
        output.writeInt(tuple.getSourceTask(), true);
        output.writeInt(_ids.getStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()), true);
        if (isBatchTuple) {
            List<Object> values = tuple.getValues();
            int len = values.size();
            output.writeInt(len, true);
            if (_ackerNum > 0) {
                for (Object value : values) {
                    Pair<MessageId, List<Object>> pairValue = (Pair<MessageId, List<Object>>) value;
                    if (pairValue.getFirst() != null) {
                        pairValue.getFirst().serialize(output);
                    } else {
                        output.writeInt(0, true);
                    }
                    _kryo.serializeInto(pairValue.getSecond(), output);
                }
            } else {
                for (Object value : values) {
                    Pair<MessageId, List<Object>> pairValue = (Pair<MessageId, List<Object>>) value;
                    _kryo.serializeInto(pairValue.getSecond(), output);
                }
            }
        } else {
            MessageId msgId = tuple.getMessageId();
            if (msgId != null) {
                msgId.serialize(output);
            } else {
                output.writeInt(0, true);
            }
            _kryo.serializeInto(tuple.getValues(), output);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : TupleExt(backtype.storm.tuple.TupleExt) List(java.util.List) IOException(java.io.IOException) Pair(com.alibaba.jstorm.utils.Pair) MessageId(backtype.storm.tuple.MessageId)

Example 14 with MessageId

use of backtype.storm.tuple.MessageId in project jstorm by alibaba.

the class SpoutCollector method sendCtrlMsg.

protected List<Integer> sendCtrlMsg(String out_stream_id, List<Object> values, Object message_id, Integer out_task_id) {
    final long startTime = emitTotalTimer.getTime();
    try {
        boolean needAck = (message_id != null) && (ackerNum > 0);
        Long root_id = getRootId(message_id);
        java.util.List<Integer> out_tasks = null;
        if (out_task_id != null) {
            out_tasks = sendTargets.get(out_task_id, out_stream_id, values, null, root_id);
        } else {
            out_tasks = sendTargets.get(out_stream_id, values, null, root_id);
        }
        List<Long> ackSeq = new ArrayList<Long>();
        for (Integer t : out_tasks) {
            MessageId msgid;
            if (needAck) {
                // Long as = MessageId.generateId();
                Long as = MessageId.generateId(random);
                msgid = MessageId.makeRootId(root_id, as);
                ackSeq.add(as);
            } else {
                msgid = null;
            }
            TupleImplExt tp = new TupleImplExt(topology_context, values, task_id, out_stream_id, msgid);
            tp.setTargetTaskId(t);
            transferCtr(tp);
        }
        sendMsgToAck(out_stream_id, values, message_id, root_id, ackSeq, needAck);
        return out_tasks;
    } finally {
        emitTotalTimer.updateTime(startTime);
    }
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) ArrayList(java.util.ArrayList) MessageId(backtype.storm.tuple.MessageId)

Example 15 with MessageId

use of backtype.storm.tuple.MessageId in project storm by nathanmarz.

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(backtype.storm.tuple.TupleImpl) MessageId(backtype.storm.tuple.MessageId)

Aggregations

MessageId (backtype.storm.tuple.MessageId)15 TupleImplExt (backtype.storm.tuple.TupleImplExt)10 List (java.util.List)7 Pair (com.alibaba.jstorm.utils.Pair)6 Tuple (backtype.storm.tuple.Tuple)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 TupleExt (backtype.storm.tuple.TupleExt)3 TimerTrigger (com.alibaba.jstorm.daemon.worker.timer.TimerTrigger)2 RotatingMap (com.alibaba.jstorm.utils.RotatingMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 IRichBatchBolt (backtype.storm.topology.IRichBatchBolt)1 TupleImpl (backtype.storm.tuple.TupleImpl)1 BatchSnapshot (com.alibaba.jstorm.transactional.BatchSnapshot)1