Example usage for io.netty.channel ChannelPipeline addLast

List of usage examples for io.netty.channel ChannelPipeline addLast

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline addLast.

Prototype

ChannelPipeline addLast(ChannelHandler... handlers);

Source Link

Document

Inserts ChannelHandler s at the last position of this pipeline.

Usage

From source file:com.codeabovelab.dm.platform.http.async.NettyRequestFactory.java

License:Apache License

private Bootstrap getBootstrap() {
    if (this.bootstrap == null) {
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override//from   ww  w .  j ava  2  s. c  om
                    protected void initChannel(SocketChannel channel) throws Exception {
                        configureChannel(channel.config());
                        ChannelPipeline pipeline = channel.pipeline();
                        if (sslContext != null) {
                            pipeline.addLast(sslContext.newHandler(channel.alloc()));
                        }
                        pipeline.addLast(new HttpClientCodec());
                        //pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
                        if (readTimeout > 0) {
                            pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS));
                        }
                    }
                });
        this.bootstrap = bootstrap;
    }
    return this.bootstrap;
}

From source file:com.common.server.ScheduleServer.java

License:Apache License

public void startServer() throws Exception {
    try {/*w  w w. ja va  2s  . co  m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        //p.addLast(new LoggingHandler(LogLevel.INFO));
                        p.addLast(new ScheduleServerHandler());
                    }
                });

        // Start the server.
        ChannelFuture f = b.bind(this.port).sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.couchbase.client.core.endpoint.AbstractEndpoint.java

License:Apache License

/**
 * Create a new {@link AbstractEndpoint}.
 *
 * @param hostname the hostname/ipaddr of the remote channel.
 * @param bucket the name of the bucket.
 * @param password the password of the bucket.
 * @param port the port of the remote channel.
 * @param environment the environment of the core.
 * @param responseBuffer the response buffer for passing responses up the stack.
 *//*  w ww. j  a  v  a 2 s  . c  o m*/
protected AbstractEndpoint(final String hostname, final String bucket, final String password, final int port,
        final CoreEnvironment environment, final RingBuffer<ResponseEvent> responseBuffer,
        boolean isTransient) {
    super(LifecycleState.DISCONNECTED);
    this.bucket = bucket;
    this.password = password;
    this.responseBuffer = responseBuffer;
    this.env = environment;
    this.isTransient = isTransient;
    if (environment.sslEnabled()) {
        this.sslEngineFactory = new SSLEngineFactory(environment);
    }

    Class<? extends Channel> channelClass = NioSocketChannel.class;
    if (environment.ioPool() instanceof EpollEventLoopGroup) {
        channelClass = EpollSocketChannel.class;
    } else if (environment.ioPool() instanceof OioEventLoopGroup) {
        channelClass = OioSocketChannel.class;
    }

    ByteBufAllocator allocator = env.bufferPoolingEnabled() ? PooledByteBufAllocator.DEFAULT
            : UnpooledByteBufAllocator.DEFAULT;

    boolean tcpNodelay = environment().tcpNodelayEnabled();
    bootstrap = new BootstrapAdapter(
            new Bootstrap().remoteAddress(hostname, port).group(environment.ioPool()).channel(channelClass)
                    .option(ChannelOption.ALLOCATOR, allocator).option(ChannelOption.TCP_NODELAY, tcpNodelay)
                    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, env.socketConnectTimeout())
                    .handler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel channel) throws Exception {
                            ChannelPipeline pipeline = channel.pipeline();
                            if (environment.sslEnabled()) {
                                pipeline.addLast(new SslHandler(sslEngineFactory.get()));
                            }
                            if (LOGGER.isTraceEnabled()) {
                                pipeline.addLast(LOGGING_HANDLER_INSTANCE);
                            }
                            customEndpointHandlers(pipeline);
                        }
                    }));
}

From source file:com.couchbase.client.core.endpoint.binary.BinaryEndpoint.java

License:Open Source License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    pipeline.addLast(new BinaryMemcacheClientCodec())
            .addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE))
            .addLast(new BinarySaslClient(bucket(), password(), this)).addLast(new BinaryCodec());
}

From source file:com.couchbase.client.core.endpoint.config.ConfigEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpClientCodec()).addLast(new ConfigHandler(this, responseBuffer(), true));
}

From source file:com.couchbase.client.core.endpoint.dcp.DCPEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(ChannelPipeline pipeline) {
    pipeline.addLast(new BinaryMemcacheClientCodec())
            .addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE))
            .addLast(new KeyValueAuthHandler(bucket(), password()))
            .addLast(new DCPConnectionHandler(environment()))
            .addLast(new DCPHandler(this, responseBuffer(), false));
}

From source file:com.couchbase.client.core.endpoint.kv.KeyValueEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    if (environment().keepAliveInterval() > 0) {
        pipeline.addLast(new IdleStateHandler(environment().keepAliveInterval(), 0, 0, TimeUnit.MILLISECONDS));
    }/*from   w w  w.  ja  va 2  s  . com*/
    pipeline.addLast(new BinaryMemcacheClientCodec())
            .addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE))
            .addLast(new KeyValueAuthHandler(bucket(), password()))
            .addLast(new KeyValueFeatureHandler(environment()))
            .addLast(new KeyValueHandler(this, responseBuffer(), false));
}

From source file:com.couchbase.client.core.endpoint.query.QueryEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    if (environment().keepAliveInterval() > 0) {
        pipeline.addLast(new IdleStateHandler(environment().keepAliveInterval(), 0, 0, TimeUnit.MILLISECONDS));
    }//  ww w  .  ja  v a 2  s  . c  o  m
    pipeline.addLast(new HttpClientCodec()).addLast(new QueryHandler(this, responseBuffer(), false));
}

From source file:com.couchbase.client.core.endpoint.search.SearchEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    if (environment().keepAliveInterval() > 0) {
        pipeline.addLast(new IdleStateHandler(environment().keepAliveInterval(), 0, 0, TimeUnit.MILLISECONDS));
    }/*from w ww.j a va  2 s  . c  om*/
    pipeline.addLast(new HttpClientCodec()).addLast(new SearchHandler(this, responseBuffer(), false));
}

From source file:com.couchbase.client.core.endpoint.view.ViewEndpoint.java

License:Apache License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    if (environment().keepAliveInterval() > 0) {
        pipeline.addLast(new IdleStateHandler(environment().keepAliveInterval(), 0, 0, TimeUnit.MILLISECONDS));
    }//  w ww  .j  a  va2  s  .  co m
    pipeline.addLast(new HttpClientCodec()).addLast(new ViewHandler(this, responseBuffer(), false));
}