Search in sources :

Example 6 with MessageId

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

the class BoltCollector method sendCtrlMsg.

protected List<Integer> sendCtrlMsg(String out_stream_id, List<Object> values, Collection<Tuple> anchors, Integer out_task_id) {
    final long start = emitTimer.getTime();
    java.util.List<Integer> out_tasks = null;
    try {
        if (out_task_id != null) {
            out_tasks = sendTargets.get(out_task_id, out_stream_id, values, anchors, null);
        } else {
            out_tasks = sendTargets.get(out_stream_id, values, anchors, null);
        }
        tryRotate();
        for (Integer t : out_tasks) {
            MessageId msgid = getMessageId(anchors);
            TupleImplExt tp = new TupleImplExt(topologyContext, values, task_id, out_stream_id, msgid);
            tp.setTargetTaskId(t);
            transferCtr(tp);
        }
    } catch (Exception e) {
        LOG.error("bolt emit", e);
    } finally {
        emitTimer.updateTime(start);
    }
    return out_tasks;
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) MessageId(backtype.storm.tuple.MessageId)

Example 7 with MessageId

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

the class BoltCollector method sendMsg.

public List<Integer> sendMsg(String out_stream_id, List<Object> values, Collection<Tuple> anchors, Integer out_task_id, ICollectorCallback callback) {
    final long start = emitTimer.getTime();
    List<Integer> outTasks = null;
    try {
        if (out_task_id != null) {
            outTasks = sendTargets.get(out_task_id, out_stream_id, values, anchors, null);
        } else {
            outTasks = sendTargets.get(out_stream_id, values, anchors, null);
        }
        tryRotate();
        for (Integer t : outTasks) {
            MessageId msgid = getMessageId(anchors);
            TupleImplExt tp = new TupleImplExt(topologyContext, values, task_id, out_stream_id, msgid);
            tp.setTargetTaskId(t);
            taskTransfer.transfer(tp);
        }
    } catch (Exception e) {
        LOG.error("bolt emit", e);
    } finally {
        if (outTasks == null) {
            outTasks = new ArrayList<Integer>();
        }
        if (callback != null)
            callback.execute(out_stream_id, outTasks, values);
        emitTimer.updateTime(start);
    }
    return outTasks;
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) MessageId(backtype.storm.tuple.MessageId)

Example 8 with MessageId

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

the class BoltExecutors method processTupleBatchEvent.

private void processTupleBatchEvent(Tuple tuple) {
    try {
        if ((!isSystemBolt && tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID)) || tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID)) {
            if (tuple.getValues().get(0) instanceof Pair) {
                for (Object value : tuple.getValues()) {
                    Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
                    TupleImplExt t = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) tuple));
                    processTupleEvent(t);
                }
            }
        } else {
            bolt.execute(tuple);
        }
    } catch (Throwable e) {
        error = e;
        LOG.error("bolt execute error ", e);
        report_error.report(e);
    }
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) List(java.util.List) Pair(com.alibaba.jstorm.utils.Pair) MessageId(backtype.storm.tuple.MessageId)

Example 9 with MessageId

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

the class BoltExecutors method onEvent.

@Override
public void onEvent(Object event, long sequence, boolean endOfBatch) throws Exception {
    if (event == null) {
        return;
    }
    long start = System.currentTimeMillis();
    try {
        if (event instanceof Tuple) {
            Tuple tuple = (Tuple) event;
            int tupleNum = 1;
            Long startTime = System.currentTimeMillis();
            long lifeCycleStart = ((TupleExt) tuple).getCreationTimeStamp();
            task_stats.tupleLifeCycle(tuple.getSourceComponent(), tuple.getSourceStreamId(), lifeCycleStart, startTime);
            if (((TupleExt) tuple).isBatchTuple()) {
                List<Object> values = ((Tuple) event).getValues();
                tupleNum = values.size();
                if (bolt instanceof IRichBatchBolt) {
                    processControlEvent();
                    processTupleBatchEvent(tuple);
                } else {
                    for (Object value : values) {
                        Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
                        TupleImplExt t = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) event));
                        processControlEvent();
                        processTupleEvent(t);
                    }
                }
            } else {
                processTupleEvent(tuple);
            }
            task_stats.recv_tuple(tuple.getSourceComponent(), tuple.getSourceStreamId(), tupleNum);
            if (ackerNum == 0) {
                // get tuple process latency
                if (JStormMetrics.enabled) {
                    long endTime = System.currentTimeMillis();
                    task_stats.update_bolt_acked_latency(tuple.getSourceComponent(), tuple.getSourceStreamId(), startTime, endTime, tupleNum);
                }
            }
        } else if (event instanceof TimerTrigger.TimerEvent) {
            processTimerEvent((TimerTrigger.TimerEvent) event);
        } else {
            LOG.warn("Bolt executor received unknown message");
        }
    } finally {
        if (JStormMetrics.enabled) {
            exeTime = System.currentTimeMillis() - start;
        }
    }
}
Also used : TupleExt(backtype.storm.tuple.TupleExt) IRichBatchBolt(backtype.storm.topology.IRichBatchBolt) 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 10 with MessageId

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

the class TransactionBolt method processBatchTuple.

public void processBatchTuple(Tuple batchEvent) {
    String stream = batchEvent.getSourceStreamId();
    if (stream.equals(TransactionCommon.BARRIER_STREAM_ID)) {
        Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) batchEvent.getValue(0);
        BatchSnapshot snapshot = (BatchSnapshot) val.getSecond().get(1);
        currentBatchTracker.receiveBarrier(batchEvent.getSourceTask());
        currentBatchTracker.expectedTupleCount += snapshot.getTupleCount();
        LOG.debug("Received batch, stream={}, batchGroupId={}, sourceTask={}, values={}", stream, currentBatchTracker.bactchGroupId, batchEvent.getSourceTask(), snapshot);
        LOG.debug("currentBatchTracker={}, processingBatches={}, pendingBatches={}", currentBatchTracker, processingBatches, batchCache);
    } else {
        for (Object value : batchEvent.getValues()) {
            /*List<Object> firstTupleValue = ((Pair<MessageId, List<Object>>) value).getSecond();
                BatchGroupId batchGroupId = (BatchGroupId) firstTupleValue.get(0);
                if (!batchGroupId.equals(currentBatchTracker.bactchGroupId)) {
                    LOG.warn("batchgroupid-{} is not equal to the once of current batch tracker-{}!", batchGroupId, currentBatchTracker.bactchGroupId);
                }*/
            Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
            val.getSecond().remove(0);
            TupleImplExt tuple = new TupleImplExt(topologyContext, val.getSecond(), val.getFirst(), ((TupleImplExt) batchEvent));
            boltExecutor.execute(tuple);
        }
        currentBatchTracker.incrementReceivedCount(batchEvent.getValues().size());
    }
    if (currentBatchTracker.checkFinish()) {
        finishCurrentBatch();
    }
}
Also used : TupleImplExt(backtype.storm.tuple.TupleImplExt) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.alibaba.jstorm.utils.Pair) MessageId(backtype.storm.tuple.MessageId) BatchSnapshot(com.alibaba.jstorm.transactional.BatchSnapshot)

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