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);
}
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);
}
}
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();
}
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;
}
}
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!!!!!!!!!!!!!");
}
Aggregations