Search in sources :

Example 1 with TaskMessage

use of backtype.storm.messaging.TaskMessage in project storm by nathanmarz.

the class MessageBatch method remove.

void remove(Object obj) {
    if (obj == null)
        return;
    if (obj instanceof TaskMessage) {
        TaskMessage msg = (TaskMessage) obj;
        msgs.remove(msg);
        encoded_length -= msgEncodeLength(msg);
        return;
    }
    if (obj instanceof ControlMessage) {
        ControlMessage msg = (ControlMessage) obj;
        msgs.remove(msg);
        encoded_length -= msg.encodeLength();
        return;
    }
}
Also used : TaskMessage(backtype.storm.messaging.TaskMessage)

Example 2 with TaskMessage

use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.

the class NettyServer method sendFlowCtrlResp.

private void sendFlowCtrlResp(Channel channel, int taskId) {
    //channel.setReadable(false);
    // send back backpressure flow control request to source client
    ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE + 1);
    // 1-> start flow control; 0-> stop flow control
    buffer.put((byte) 1);
    buffer.putInt(taskId);
    TaskMessage flowCtrlMsg = new TaskMessage(TaskMessage.BACK_PRESSURE_REQUEST, 1, buffer.array());
    channel.write(flowCtrlMsg);
//LOG.debug("Send flow ctrl resp to address({}) for task-{}", channel.getRemoteAddress().toString(), taskId);
//channel.setReadable(true);
}
Also used : ByteBuffer(java.nio.ByteBuffer) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 3 with TaskMessage

use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.

the class VirtualPortCtrlDispatch method handleEvent.

@Override
public void handleEvent(Object event, boolean endOfBatch) throws Exception {
    TaskMessage message = (TaskMessage) event;
    int task = message.task();
    Object tuple = null;
    try {
        // there might be errors when calling update_topology
        tuple = deserialize(message.message(), task);
    } catch (Throwable e) {
        if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e))
            throw new RuntimeException(e);
        LOG.warn("serialize msg error", e);
    }
    DisruptorQueue queue = controlQueues.get(task);
    if (queue == null) {
        LOG.warn("Received invalid control message for task-{}, Dropping...{} ", task, tuple);
        return;
    }
    if (tuple != null) {
        queue.publish(tuple);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) DisruptorQueue(backtype.storm.utils.DisruptorQueue) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 4 with TaskMessage

use of backtype.storm.messaging.TaskMessage 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 {
            // there might be errors when calling 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(TaskMessage.CONTROL_MESSAGE, targetTask, tupleMessage);
        conn.sendDirect(message);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) IConnection(backtype.storm.messaging.IConnection) ITupleExt(backtype.storm.tuple.ITupleExt) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 5 with TaskMessage

use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.

the class TransferDrainer method getBundleIterator.

private Iterator<TaskMessage> getBundleIterator(final ArrayList<ArrayList<TaskMessage>> bundle) {
    if (null == bundle) {
        return null;
    }
    return new Iterator<TaskMessage>() {

        private int offset = 0;

        private int size = 0;

        {
            for (ArrayList<TaskMessage> list : bundle) {
                size += list.size();
            }
        }

        private int bundleOffset = 0;

        private Iterator<TaskMessage> iter = bundle.get(bundleOffset).iterator();

        @Override
        public boolean hasNext() {
            return offset < size;
        }

        @Override
        public TaskMessage next() {
            TaskMessage msg;
            if (iter.hasNext()) {
                msg = iter.next();
            } else {
                bundleOffset++;
                iter = bundle.get(bundleOffset).iterator();
                msg = iter.next();
            }
            if (null != msg) {
                offset++;
            }
            return msg;
        }

        @Override
        public void remove() {
            throw new RuntimeException("not supported");
        }
    };
}
Also used : Iterator(java.util.Iterator) TaskMessage(backtype.storm.messaging.TaskMessage)

Aggregations

TaskMessage (backtype.storm.messaging.TaskMessage)31 IConnection (backtype.storm.messaging.IConnection)15 Test (org.junit.Test)12 IContext (backtype.storm.messaging.IContext)7 ControlMessage (backtype.storm.messaging.ControlMessage)4 ByteBuffer (java.nio.ByteBuffer)4 ITupleExt (backtype.storm.tuple.ITupleExt)2 KryoException (com.esotericsoftware.kryo.KryoException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 ChannelBufferOutputStream (org.jboss.netty.buffer.ChannelBufferOutputStream)2 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 AsmHistogram (com.alibaba.jstorm.common.metric.AsmHistogram)1 Iterator (java.util.Iterator)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Channel (org.jboss.netty.channel.Channel)1