Search in sources :

Example 21 with Tuple

use of backtype.storm.tuple.Tuple 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 22 with Tuple

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

the class CtrlEventDispatcher method process.

@Override
public void process(Object event) throws Exception {
    if (event instanceof UpdateConfigEvent) {
        update(((UpdateConfigEvent) event).getConf());
        return;
    }
    Tuple input = (Tuple) event;
    TopoMasterCtrlEvent ctlEvent = (TopoMasterCtrlEvent) input.getValues().get(0);
    if (ctlEvent != null) {
        if (ctlEvent.isTransactionEvent()) {
            snapshotStateMaster.process(input);
        } else {
            String errorInfo = "Received unexpected control event, {}" + event.toString();
            LOG.warn(errorInfo);
            zkCluster.report_task_error(context.getTopologyId(), context.getThisTaskId(), errorInfo, ErrorConstants.WARN, ErrorConstants.CODE_USER);
        }
    }
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Example 23 with Tuple

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

the class TaskHeartbeatUpdater method process.

@Override
public void process(Object event) throws Exception {
    synchronized (_lock) {
        if (event instanceof UpdateConfigEvent) {
            update(((UpdateConfigEvent) event).getConf());
            return;
        }
        Tuple input = (Tuple) event;
        int sourceTask = input.getSourceTask();
        int uptime = (Integer) input.getValue(0);
        TaskStatus executorStatus = new TaskStatus();
        if (input.getValues().size() < 2) {
            // for compatibility
            executorStatus.setStatus(TaskStatus.RUN);
        } else {
            executorStatus.setStatus((byte) input.getValue(1));
        }
        boolean isSendSpoutTaskFinishStream = false;
        if (spoutsExecutorStatusMap.containsKey(sourceTask)) {
            spoutsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (boltsExecutorStatusMap.containsKey(sourceTask)) {
            boltsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (sourceTask != taskId) {
            LOG.warn("received invalid task heartbeat {}", input);
        }
        if (executorStatus.getStatus() == TaskStatus.INIT && spoutsExecutorStatusMap.get(sourceTask) != null) {
            boolean existInitStatusBolt = false;
            for (TaskStatus status : boltsExecutorStatusMap.values()) {
                if (status.getStatus() == TaskStatus.INIT || status.getStatus() == TaskStatus.SHUTDOWN) {
                    existInitStatusBolt = true;
                    break;
                }
            }
            if (!existInitStatusBolt)
                isSendSpoutTaskFinishStream = true;
        }
        if (client == null) {
            client = new NimbusClientWrapper();
            client.init(stormConf);
        }
        // Update the heartbeat for source task, but don't update it if task is initial status
        if (executorStatus.getStatus() != TaskStatus.INIT && uptime > 0) {
            TaskHeartbeat taskHb = taskHbMap.get().get(sourceTask);
            if (taskHb == null) {
                taskHb = new TaskHeartbeat(TimeUtils.current_time_secs(), uptime);
                TaskHeartbeat tmpTaskHb = taskHbMap.get().putIfAbsent(sourceTask, taskHb);
                if (tmpTaskHb != null) {
                    taskHb = tmpTaskHb;
                }
            }
            taskHb.set_time(TimeUtils.current_time_secs());
            taskHb.set_uptime(uptime);
        } else if (isSendSpoutTaskFinishStream) {
            TopoMasterCtrlEvent finishInitEvent = new TopoMasterCtrlEvent(TopoMasterCtrlEvent.EventType.topologyFinishInit);
            ((BoltCollector) (collector.getDelegate())).emitDirectCtrl(sourceTask, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(finishInitEvent));
            LOG.info("all bolts' task finish init operation, so tm will notify the spout task-{}", sourceTask);
        }
        // Send heartbeat info of all tasks to nimbus
        if (sourceTask == taskId) {
            uploadHB();
        }
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) NimbusClientWrapper(backtype.storm.utils.NimbusClientWrapper) Values(backtype.storm.tuple.Values) UpdateConfigEvent(com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent) TaskStatus(com.alibaba.jstorm.task.TaskStatus) Tuple(backtype.storm.tuple.Tuple)

Example 24 with Tuple

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

the class MetricsUpdater method process.

@Override
public void process(Object event) {
    Tuple input = (Tuple) event;
    updateMetrics(input);
}
Also used : Tuple(backtype.storm.tuple.Tuple)

Example 25 with Tuple

use of backtype.storm.tuple.Tuple 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)

Aggregations

Tuple (backtype.storm.tuple.Tuple)49 Values (backtype.storm.tuple.Values)11 ArrayList (java.util.ArrayList)10 MessageId (backtype.storm.tuple.MessageId)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Message (com.yahoo.pulsar.client.api.Message)4 TupleImpl (backtype.storm.tuple.TupleImpl)3 TupleImplExt (backtype.storm.tuple.TupleImplExt)3 Pair (com.alibaba.jstorm.utils.Pair)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GlobalStreamId (backtype.storm.generated.GlobalStreamId)2 FailedException (backtype.storm.topology.FailedException)2 TupleExt (backtype.storm.tuple.TupleExt)2 TimerTrigger (com.alibaba.jstorm.daemon.worker.timer.TimerTrigger)2 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)2 RotatingMap (com.alibaba.jstorm.utils.RotatingMap)2 Pair (com.alipay.dw.jstorm.example.sequence.bean.Pair)2 TradeCustomer (com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)2