use of org.apache.storm.generated.HBServerMessageType 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