use of org.apache.storm.messaging.netty.SaslMessageToken in project storm by apache.
the class ThriftDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
long available = buf.readableBytes();
if (available < INTEGER_SIZE) {
return null;
}
buf.markReaderIndex();
int thriftLen = buf.readInt();
available -= INTEGER_SIZE;
if (available < thriftLen) {
// We haven't received the entire object yet, return and wait for more bytes.
buf.resetReaderIndex();
return null;
}
byte[] serialized = new byte[thriftLen];
buf.readBytes(serialized, 0, thriftLen);
HBMessage m = (HBMessage) Utils.thriftDeserialize(HBMessage.class, serialized);
if (m.get_type() == HBServerMessageType.CONTROL_MESSAGE) {
ControlMessage cm = ControlMessage.read(m.get_data().get_message_blob());
return cm;
} else if (m.get_type() == HBServerMessageType.SASL_MESSAGE_TOKEN) {
SaslMessageToken sm = SaslMessageToken.read(m.get_data().get_message_blob());
return sm;
} else {
return m;
}
}
use of org.apache.storm.messaging.netty.SaslMessageToken in project storm by apache.
the class ThriftEncoder method encode.
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
if (msg == null) {
return null;
}
LOG.debug("Trying to encode: " + msg.getClass().toString() + " : " + msg.toString());
HBMessage m;
if (msg instanceof INettySerializable) {
INettySerializable nettyMsg = (INettySerializable) msg;
HBServerMessageType type;
if (msg instanceof ControlMessage) {
type = HBServerMessageType.CONTROL_MESSAGE;
} else if (msg instanceof SaslMessageToken) {
type = HBServerMessageType.SASL_MESSAGE_TOKEN;
} else {
LOG.error("Didn't recognise INettySerializable: " + nettyMsg.toString());
throw new RuntimeException("Unrecognized INettySerializable.");
}
m = encodeNettySerializable(nettyMsg, type);
} else {
m = (HBMessage) msg;
}
try {
byte[] serialized = Utils.thriftSerialize(m);
ChannelBuffer ret = ChannelBuffers.directBuffer(serialized.length + 4);
ret.writeInt(serialized.length);
ret.writeBytes(serialized);
return ret;
} catch (RuntimeException e) {
LOG.error("Failed to serialize.", e);
throw e;
}
}
Aggregations