/**
* Returns a new channel initializer suited to encode and decode a protocol
* buffer message.
* <p/>
* <p>Message sizes over 10 MB are not supported.</p>
* <p/>
* <p>The handler will be executed on the I/O thread. Blocking operations
* should be executed in their own thread.</p>
*
* @param defaultInstance an instance of the message to handle
* @param handler the handler implementing the application logic
* @param <M> the type of the support protocol buffer message
*/
public static final <M extends Message> ChannelInitializer<Channel> protoBuf(
final M defaultInstance, final SimpleChannelInboundHandler<M> handler) {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast("frameDecoder",
new LengthFieldBasedFrameDecoder(10 * 1024 * 1024, 0, 4, 0, 4));
channel.pipeline().addLast("protobufDecoder",
new ProtobufDecoder(defaultInstance));
channel.pipeline().addLast("frameEncoder", new LengthFieldPrepender(4));
channel.pipeline().addLast("protobufEncoder", new ProtobufEncoder());
channel.pipeline().addLast("applicationHandler", handler);
}
};
}
ChannelInitializers.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:piezo
作者:
评论列表
文章目录