Example usage for io.netty.channel SimpleChannelInboundHandler isSharable

List of usage examples for io.netty.channel SimpleChannelInboundHandler isSharable

Introduction

In this page you can find the example usage for io.netty.channel SimpleChannelInboundHandler isSharable.

Prototype

public boolean isSharable() 

Source Link

Document

Return true if the implementation is Sharable and so can be added to different ChannelPipeline s.

Usage

From source file:io.soliton.protobuf.ChannelInitializers.java

License:Apache License

/**
 * Returns a new chanel initializer suited to decode and process HTTP
 * requests.//from  w  w  w .  j a  v a  2 s .  c  om
 *
 * @param handler the handler implementing the application logic
 */
public static final ChannelInitializer<Channel> httpServer(
        final SimpleChannelInboundHandler<HttpRequest> handler) {
    Preconditions.checkArgument(handler.isSharable());
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel channel) throws Exception {
            ChannelPipeline pipeline = channel.pipeline();
            pipeline.addLast("httpCodec", new HttpServerCodec());
            pipeline.addLast("aggregator", new HttpObjectAggregator(10 * 1024 * 1024));
            pipeline.addLast("httpServerHandler", handler);
        }
    };
}