Add ByteToMessageCodec.isEncodable()

This commit is contained in:
Trustin Lee 2013-01-09 14:26:15 +09:00
parent dd6b7969b7
commit aa69d628f1

View File

@ -27,24 +27,25 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
extends ChannelHandlerAdapter extends ChannelHandlerAdapter
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<OUTBOUND_IN> { implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<OUTBOUND_IN> {
private final MessageToByteEncoder<OUTBOUND_IN> encoder = private final MessageToByteEncoder<OUTBOUND_IN> encoder;
new MessageToByteEncoder<OUTBOUND_IN>() { private final ByteToMessageDecoder<INBOUND_OUT> decoder;
protected ByteToMessageCodec(Class<?>... encodableMessageTypes) {
encoder = new MessageToByteEncoder<OUTBOUND_IN>(encodableMessageTypes) {
@Override @Override
public void encode( protected void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception {
ChannelHandlerContext ctx,
OUTBOUND_IN msg, ByteBuf out) throws Exception {
ByteToMessageCodec.this.encode(ctx, msg, out); ByteToMessageCodec.this.encode(ctx, msg, out);
} }
}; };
private final ByteToMessageDecoder<INBOUND_OUT> decoder = decoder = new ByteToMessageDecoder<INBOUND_OUT>() {
new ByteToMessageDecoder<INBOUND_OUT>() {
@Override @Override
public INBOUND_OUT decode( public INBOUND_OUT decode(
ChannelHandlerContext ctx, ByteBuf in) throws Exception { ChannelHandlerContext ctx, ByteBuf in) throws Exception {
return ByteToMessageCodec.this.decode(ctx, in); return ByteToMessageCodec.this.decode(ctx, in);
} }
}; };
}
@Override @Override
public ByteBuf newInboundBuffer( public ByteBuf newInboundBuffer(
@ -79,10 +80,10 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
encoder.freeOutboundBuffer(ctx); encoder.freeOutboundBuffer(ctx);
} }
protected abstract void encode( protected boolean isEncodable(Object msg) throws Exception {
ChannelHandlerContext ctx, return encoder.isEncodable(msg);
OUTBOUND_IN msg, ByteBuf out) throws Exception; }
protected abstract INBOUND_OUT decode( protected abstract void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception;
ChannelHandlerContext ctx, ByteBuf in) throws Exception; protected abstract INBOUND_OUT decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
} }