Search in sources :

Example 1 with ITupleExt

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

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

the class DrainerCtrlRunable method handleEvent.

@Override
public void handleEvent(Object event, boolean endOfBatch) throws Exception {
    if (event == null) {
        return;
    }
    ITupleExt tuple = (ITupleExt) event;
    int targetTask = tuple.getTargetTaskId();
    IConnection conn = getConnection(targetTask);
    if (conn != null) {
        byte[] tupleMessage = null;
        try {
            //it maybe happened errors when update_topology
            tupleMessage = serialize(tuple);
        } catch (Throwable e) {
            if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e)) {
                throw new RuntimeException(e);
            } else {
                LOG.warn("serialize happened errors!!!", e);
            }
        }
        TaskMessage message = new TaskMessage((short) TaskMessage.CONTROL_MESSAGE, targetTask, tupleMessage);
        conn.send(message);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) IConnection(backtype.storm.messaging.IConnection) ITupleExt(backtype.storm.tuple.ITupleExt) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 3 with ITupleExt

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

the class TaskTransfer method serialize.

protected void serialize(KryoTupleSerializer serializer, Object event) {
    long start = serializeTimer.getTime();
    try {
        ITupleExt tuple = (ITupleExt) event;
        int targetTaskid = tuple.getTargetTaskId();
        IConnection conn = getConnection(targetTaskid);
        if (conn != null) {
            byte[] tupleMessage = serializer.serialize((TupleExt) tuple);
            //LOG.info("Task-{} sent msg to task-{}, data={}", task.getTaskId(), taskid, JStormUtils.toPrintableString(tupleMessage));
            TaskMessage taskMessage = new TaskMessage(targetTaskid, tupleMessage);
            conn.send(taskMessage);
        } else {
            LOG.error("Can not find connection for task-{}", targetTaskid);
        }
    } finally {
        if (MetricUtils.metricAccurateCal)
            serializeTimer.updateTime(start);
    }
}
Also used : IConnection(backtype.storm.messaging.IConnection) ITupleExt(backtype.storm.tuple.ITupleExt) TaskMessage(backtype.storm.messaging.TaskMessage)

Aggregations

ITupleExt (backtype.storm.tuple.ITupleExt)3 IConnection (backtype.storm.messaging.IConnection)2 TaskMessage (backtype.storm.messaging.TaskMessage)2 KryoTupleSerializer (backtype.storm.serialization.KryoTupleSerializer)1 TupleExt (backtype.storm.tuple.TupleExt)1 KryoException (com.esotericsoftware.kryo.KryoException)1