// Read the length field.
int length = buf.readInt();
if (length <= 0) {
LOG.info("Receive one message whose TaskMessage's message length is {}", length);
return new TaskMessage(task, null);
}
// Make sure if there's enough bytes in the buffer.
available -= 4;
if (available < length) {
// The whole bytes were not received yet - return null.
buf.resetReaderIndex();
return null;
}
// There's enough bytes in the buffer. Read it.
ChannelBuffer payload = buf.readBytes(length);
// Successfully decoded a frame.
// Return a TaskMessage object
byte[] rawBytes = payload.array();
// @@@ TESTING CODE
// LOG.info("Receive task:{}, length: {}, data:{}",
// task, length, JStormUtils.toPrintableString(rawBytes));
TaskMessage ret = new TaskMessage(task, rawBytes);
return ret;
} finally {
if (timer != null) timer.stop();
}