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(EventExecutorGroup group, ChannelHandler... handlers);

Source Link

Document

Inserts ChannelHandler s at the last position of this pipeline.

Usage

From source file:com.gxkj.demo.netty.socksproxy.SocksServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline channelPipeline = socketChannel.pipeline();

    channelPipeline.addLast(SocksInitRequestDecoder.getName(), new SocksInitRequestDecoder());

    channelPipeline.addLast(SocksMessageEncoder.getName(), socksMessageEncoder);

    channelPipeline.addLast(SocksServerHandler.getName(), socksServerHandler);
}

From source file:com.gxkj.demo.netty.telnet.TelnetClientInitializer.java

License:Apache License

/**
 * ChannelChannelChannelPipeline//  w  ww .j a v a 2 s.  c  o m
 * This method will be called once the {@link Channel} was registered. After the method returns this instance
 * will be removed from the {@link ChannelPipeline} of the {@link Channel}.
 *
 * @param ch            the {@link Channel} which was registered.
 * @throws Exception    is thrown if an error occurs. In that case the {@link Channel} will be closed.
 */
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Add the text line codec combination first,
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", DECODER);
    pipeline.addLast("encoder", ENCODER);

    // and then business logic.
    pipeline.addLast("handler", CLIENTHANDLER);
}

From source file:com.hazelcast.openshift.TunnelServer.java

License:Open Source License

@Override
protected ServerBootstrap createBootstrap(int localPort) throws Exception {
    SslContext sslContext;//from ww w . ja v  a2 s.c  o  m
    if (!ssl) {
        sslContext = null;

    } else {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslContext = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    }

    System.out.println("Creating serverside http-socket: (" + localPort + ") => (" + forwardHost + ":"
            + forwardPort + ")");
    return new ServerBootstrap().option(ChannelOption.SO_BACKLOG, 20).group(getBossGroup(), getWorkerGroup())
            .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

                @Override
                protected void initChannel(SocketChannel channel) throws Exception {
                    ChannelPipeline pipeline = channel.pipeline();
                    if (sslContext != null) {
                        pipeline.addLast("ssl", sslContext.newHandler(channel.alloc()));
                    }
                    pipeline.addLast("http-codec", new HttpServerCodec());
                    pipeline.addLast(new TunnelClientAcceptor(getWorkerGroup(), forwardHost, forwardPort));
                }
            });

}

From source file:com.hazelcast.openshift.TunnelServerConnector.java

License:Open Source License

protected Bootstrap createBootstrap(Channel socket, Promise promise) throws Exception {
    SslContext sslContext;/*from   w  w  w. j ava 2 s.  com*/
    if (!ssl) {
        sslContext = null;

    } else {
        sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    }

    return new Bootstrap().channel(NioSocketChannel.class).group(workerGroup)
            .option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

                @Override
                protected void initChannel(SocketChannel channel) throws Exception {
                    System.out.println(
                            "Configure plain-socket: (" + socket + ") => (" + httpHost + ":" + httpPort + ")");
                    ChannelPipeline pipeline = channel.pipeline();
                    if (sslContext != null) {
                        pipeline.addLast("ssl", sslContext.newHandler(channel.alloc()));
                    }
                    pipeline.addLast("http-codec", new HttpClientCodec());
                    pipeline.addLast(new TunnelServerAcceptor(socket, promise));
                }
            });
}

From source file:com.hazelcast.simulator.protocol.connector.AgentConnector.java

License:Open Source License

@Override
public void configureClientPipeline(ChannelPipeline pipeline, SimulatorAddress remoteAddress,
        ConcurrentMap<String, ResponseFuture> futureMap) {
    pipeline.addLast("responseEncoder", new ResponseEncoder(localAddress));
    pipeline.addLast("messageEncoder", new MessageEncoder(localAddress, remoteAddress));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(localAddress, workerJvmManager));
    pipeline.addLast("forwardToCoordinatorHandler",
            new ForwardToCoordinatorHandler(localAddress, connectionManager, workerJvmManager));
    pipeline.addLast("responseHandler", new ResponseHandler(localAddress, remoteAddress, getFutureMap()));
    pipeline.addLast("messageConsumeHandler", new MessageConsumeHandler(localAddress, processor));
    pipeline.addLast("exceptionHandler", new ExceptionHandler(this));
}

From source file:com.hazelcast.simulator.protocol.connector.AgentConnector.java

License:Open Source License

@Override
void configureServerPipeline(ChannelPipeline pipeline, ServerConnector serverConnector) {
    pipeline.addLast("connectionValidationHandler", new ConnectionValidationHandler());
    pipeline.addLast("connectionListenerHandler", new ConnectionListenerHandler(connectionManager));
    pipeline.addLast("responseEncoder", new ResponseEncoder(localAddress));
    pipeline.addLast("messageEncoder", new MessageEncoder(localAddress, COORDINATOR));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(localAddress));
    pipeline.addLast("forwardToWorkerHandler",
            new ForwardToWorkerHandler(localAddress, clientConnectorManager));
    pipeline.addLast("messageConsumeHandler", new MessageConsumeHandler(localAddress, processor));
    pipeline.addLast("responseHandler",
            new ResponseHandler(localAddress, COORDINATOR, futureMap, addressIndex));
    pipeline.addLast("exceptionHandler", new ExceptionHandler(this));
}

From source file:com.hazelcast.simulator.protocol.connector.AgentConnectorImpl.java

License:Open Source License

@Override
public void configureClientPipeline(ChannelPipeline pipeline, SimulatorAddress remoteAddress,
        ConcurrentMap<String, ResponseFuture> futureMap) {
    pipeline.addLast("responseEncoder", new ResponseEncoder(localAddress));
    pipeline.addLast("messageEncoder", new MessageEncoder(localAddress, remoteAddress));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(localAddress, workerProcessManager));
    pipeline.addLast("forwardToCoordinatorHandler",
            new ForwardToCoordinatorHandler(localAddress, connectionManager, workerProcessManager));
    pipeline.addLast("responseHandler", new ResponseHandler(localAddress, remoteAddress, getFutureMap()));
    pipeline.addLast("messageConsumeHandler",
            new MessageConsumeHandler(localAddress, processor, getScheduledExecutor()));
    pipeline.addLast("exceptionHandler", new ExceptionHandler(this));
}

From source file:com.hazelcast.simulator.protocol.connector.AgentConnectorImpl.java

License:Open Source License

@Override
void configureServerPipeline(ChannelPipeline pipeline, ServerConnector serverConnector) {
    pipeline.addLast("connectionListenerHandler", new ConnectionHandler(connectionManager));
    pipeline.addLast("responseEncoder", new ResponseEncoder(localAddress));
    pipeline.addLast("messageEncoder", new MessageEncoder(localAddress, COORDINATOR));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(localAddress));
    pipeline.addLast("forwardToWorkerHandler",
            new ForwardToWorkerHandler(localAddress, getClientConnectorManager()));
    pipeline.addLast("messageConsumeHandler",
            new MessageConsumeHandler(localAddress, processor, getScheduledExecutor()));
    pipeline.addLast("responseHandler",
            new ResponseHandler(localAddress, COORDINATOR, futureMap, addressIndex));
    pipeline.addLast("exceptionHandler", new ExceptionHandler(this));
}

From source file:com.hazelcast.simulator.protocol.connector.CoordinatorConnector.java

License:Open Source License

@Override
public void configureClientPipeline(ChannelPipeline pipeline, SimulatorAddress remoteAddress,
        ConcurrentMap<String, ResponseFuture> futureMap) {
    pipeline.addLast("messageEncoder", new MessageEncoder(COORDINATOR, remoteAddress));
    pipeline.addLast("responseEncoder", new ResponseEncoder(COORDINATOR));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(COORDINATOR));
    pipeline.addLast("responseHandler", new ResponseHandler(COORDINATOR, remoteAddress, futureMap));
    pipeline.addLast("messageConsumeHandler", new MessageConsumeHandler(COORDINATOR, processor));
}

From source file:com.hazelcast.simulator.protocol.connector.CoordinatorRemoteConnector.java

License:Open Source License

@Override
public void configureClientPipeline(ChannelPipeline pipeline, SimulatorAddress remoteAddress,
        ConcurrentMap<String, ResponseFuture> futureMap) {
    pipeline.addLast("messageEncoder", new MessageEncoder(REMOTE, remoteAddress));
    pipeline.addLast("responseEncoder", new ResponseEncoder(REMOTE));
    pipeline.addLast("frameDecoder", new SimulatorFrameDecoder());
    pipeline.addLast("protocolDecoder", new SimulatorProtocolDecoder(REMOTE));
    pipeline.addLast("responseHandler",
            new ResponseHandler(REMOTE, remoteAddress, futureMap, COORDINATOR_INDEX));
    pipeline.addLast("messageConsumeHandler", new MessageConsumeHandler(REMOTE, processor, executorService));
}