Search in sources :

Example 6 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 7 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 {
            //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 8 with TaskMessage

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

the class MessageBatch method buffer.

/**
     * create a buffer containing the encoding of this batch
     */
@Override
public ChannelBuffer buffer() throws Exception {
    ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encodedLength));
    for (Object msg : msgs) if (msg instanceof TaskMessage)
        writeTaskMessage(bout, (TaskMessage) msg);
    else {
        // LOG.debug("Write one non-TaskMessage {}", msg );
        ((ControlMessage) msg).write(bout);
    }
    // add a END_OF_BATCH indicator
    ControlMessage.EOB_MESSAGE.write(bout);
    // LOG.debug("ControlMessage.EOB_MESSAGE " );
    bout.close();
    return bout.buffer();
}
Also used : ChannelBufferOutputStream(org.jboss.netty.buffer.ChannelBufferOutputStream) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 9 with TaskMessage

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

the class MessageBatch method remove.

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

Example 10 with TaskMessage

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

the class NettyUnitTest method test_small_message.

@Test
public void test_small_message() {
    System.out.println("!!!!!!!!Start test_small_message !!!!!!!!!!!");
    String req_msg = "Aloha is the most Hawaiian word.";
    IConnection server = null;
    IConnection client = null;
    server = initNettyServer();
    client = context.connect(null, "localhost", port);
    List<TaskMessage> list = new ArrayList<TaskMessage>();
    TaskMessage message = new TaskMessage(task, req_msg.getBytes());
    list.add(message);
    client.send(message);
    byte[] recv = (byte[]) server.recv(task, 0);
    Assert.assertEquals(req_msg, new String(recv));
    System.out.println("!!!!!!!!!!!!!!!!!!Test one time!!!!!!!!!!!!!!!!!");
    server.close();
    client.close();
    System.out.println("!!!!!!!!!!!!End test_small_message!!!!!!!!!!!!!");
}
Also used : IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Aggregations

TaskMessage (backtype.storm.messaging.TaskMessage)30 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)3 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 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Condition (java.util.concurrent.locks.Condition)1 Channel (org.jboss.netty.channel.Channel)1