Search in sources :

Example 1 with HBServerMessageType

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;
    }
}
Also used : HBServerMessageType(org.apache.storm.generated.HBServerMessageType) SaslMessageToken(org.apache.storm.messaging.netty.SaslMessageToken) INettySerializable(org.apache.storm.messaging.netty.INettySerializable) HBMessage(org.apache.storm.generated.HBMessage) ControlMessage(org.apache.storm.messaging.netty.ControlMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

HBMessage (org.apache.storm.generated.HBMessage)1 HBServerMessageType (org.apache.storm.generated.HBServerMessageType)1 ControlMessage (org.apache.storm.messaging.netty.ControlMessage)1 INettySerializable (org.apache.storm.messaging.netty.INettySerializable)1 SaslMessageToken (org.apache.storm.messaging.netty.SaslMessageToken)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1