Search in sources :

Example 1 with TupleExt

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

the class DrainerCtrlRunable method serialize.

protected byte[] serialize(ITupleExt tuple) {
    byte[] bytes = null;
    KryoTupleSerializer kryo = atomKryoSerializer.get();
    if (kryo != null) {
        bytes = kryo.serialize((TupleExt) tuple);
    } else {
        LOG.warn("KryoTupleSerializer is null, so drop tuple...");
    }
    return bytes;
}
Also used : TupleExt(backtype.storm.tuple.TupleExt) ITupleExt(backtype.storm.tuple.ITupleExt) KryoTupleSerializer(backtype.storm.serialization.KryoTupleSerializer)

Example 2 with TupleExt

use of backtype.storm.tuple.TupleExt 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 3 with TupleExt

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

the class AckSpoutMsg method run.

public void run() {
    if (JStormDebugger.isDebug(id)) {
        LOG.info("Acking message rootId:{}, messageId:{}", id, msgId);
    }
    if (spout instanceof IAckValueSpout) {
        IAckValueSpout ackValueSpout = (IAckValueSpout) spout;
        ackValueSpout.ack(msgId, values);
    } else {
        spout.ack(msgId);
    }
    long latencyStart = tupleInfo.getTimestamp(), lifeCycleStart = 0;
    if (latencyStart != 0 && JStormMetrics.enabled) {
        long endTime = System.currentTimeMillis();
        if (tuple != null && tuple instanceof TupleExt) {
            lifeCycleStart = ((TupleExt) tuple).getCreationTimeStamp();
        }
        task_stats.spout_acked_tuple(stream, latencyStart, lifeCycleStart, endTime);
    }
}
Also used : TupleExt(backtype.storm.tuple.TupleExt) IAckValueSpout(com.alibaba.jstorm.client.spout.IAckValueSpout)

Example 4 with TupleExt

use of backtype.storm.tuple.TupleExt 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 5 with TupleExt

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

Aggregations

TupleExt (backtype.storm.tuple.TupleExt)6 List (java.util.List)4 MessageId (backtype.storm.tuple.MessageId)3 TupleImplExt (backtype.storm.tuple.TupleImplExt)3 Pair (com.alibaba.jstorm.utils.Pair)3 Tuple (backtype.storm.tuple.Tuple)2 TimerTrigger (com.alibaba.jstorm.daemon.worker.timer.TimerTrigger)2 KryoTupleSerializer (backtype.storm.serialization.KryoTupleSerializer)1 IRichBatchBolt (backtype.storm.topology.IRichBatchBolt)1 ITupleExt (backtype.storm.tuple.ITupleExt)1 Values (backtype.storm.tuple.Values)1 IAckValueSpout (com.alibaba.jstorm.client.spout.IAckValueSpout)1 IOException (java.io.IOException)1