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.mastfrog.scamper.Init.java

License:Open Source License

@Override
protected void initChannel(SctpChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(sctpMessageToBytes.get());
    pipeline.addLast(handler.get());// w  w  w  .  j a  v a 2s  .  c o m
    pipeline.addLast(processor.get());
    pipeline.addLast(proc.get());
}

From source file:com.metasoft.empire.net.websocket.WebSocketServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/* ww  w.  ja  va  2  s.  co  m*/
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    //webbrouser debug & benchmark
    //pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    //pipeline.addLast(new WebSocketServerHandler());
    //websocket protocal
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(WebSocketServer.context.getBean(WebSocketFrameHandler.class));

}

From source file:com.mikesilversides.mod1.ServerTest.EchoClient.java

License:Apache License

public static void init() throws Exception { // convert main to init
    // Configure SSL.git
    //        final SslContext sslCtx;
    if (SSL) {//from   ww w.  j  a  va 2 s . c o m
        //            sslCtx = SslContextBuilder.forClient()
        //                .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        //            sslCtx = null;
    }

    // Configure the client.
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        //                     if (sslCtx != null) {
                        //                         p.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));
                        //                     }
                        //p.addLast(new LoggingHandler(LogLevel.INFO));
                        p.addLast(new EchoClientHandler());
                    }
                });

        // Start the client.
        ChannelFuture f = b.connect(HOST, PORT).sync();

        // Wait until the connection is closed.
        f.channel().closeFuture().sync(); //Mike: I think this is a blocking wait
    } finally {
        // Shut down the event loop to terminate all threads.
        group.shutdownGracefully();
    }
}

From source file:com.mikesilversides.mod1.ServerTest.StubClient.java

License:Apache License

public void run() {
    System.out.println("StubClient.run() called!");
    // Configure the client.
    EventLoopGroup group = new NioEventLoopGroup();
    try {//from   w  w  w .j  a  v  a2s. c o  m
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();

                        p.addLast(new LoggingHandler(LogLevel.INFO));
                        p.addLast(new StubClientHandler(stubPlayer));
                    }
                });

        // Start the client.
        ChannelFuture f = b.connect(HOST, PORT).sync();

        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // We've been interrupted: no more messages.
        System.out.println("InterruptedException caught, do return");
        return;
    } finally {
        // Shut down the event loop to terminate all threads.
        System.out.println("doing group.shutdownGracefully()");
        group.shutdownGracefully();
    }
}

From source file:com.miko.s4netty.worker.WorkerInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {

    ChannelPipeline pipeline = ch.pipeline().addLast(new ReadTimeoutHandler(3000));

    logger.debug("WorkerInitializer initChannel");

    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(workerProviderHandler);
}

From source file:com.mobicage.rogerthat.plugins.news.NewsChannel.java

License:Apache License

public void connect() {
    if (TestUtils.isRunningTest()) {
        return;//from   ww w.jav a2s. c om
    }
    T.NEWS();
    if (mIsConnected) {
        L.d("Already connected to news channel");
        return;
    } else if (!mService.getNetworkConnectivityManager().isConnected()) {
        L.d("Cannot connect to news channel: no internet connection.");
        return;
    } else if (mHost == null) {
        L.d("Not connecting to news channel because no host was found");
        return;
    } else if (mPort == -1) {
        L.d("Not connecting to news channel because no port was found");
        return;
    }
    mIsRetryingToConnect = true;
    L.d("Attemping to connect to news channel...");
    final SslContext sslCtx;
    if (CloudConstants.NEWS_CHANNEL_SSL) {
        try {
            if (CloudConstants.NEWS_CHANNEL_MUST_VALIDATE_SSL_CERTIFICATE) {
                TrustManagerFactory factory = TrustManagerFactory
                        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
                KeyStore keyStore = KeyStore.getInstance("AndroidCAStore"); // Gets the default system keystore
                keyStore.load(null, null);
                factory.init(keyStore);
                sslCtx = SslContextBuilder.forClient().trustManager(factory).build();
            } else {
                sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)
                        .build();
            }
        } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
            L.bug(e);
            return;
        }
    } else {
        sslCtx = null;
    }
    if (mEventLoopGroup == null) {
        mEventLoopGroup = new NioEventLoopGroup();
    }
    Bootstrap b = new Bootstrap();
    b.group(mEventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    if (sslCtx != null) {
                        SslHandler sslHandler = sslCtx.newHandler(ch.alloc(), mHost, mPort);
                        Future<Channel> handshakeDone = sslHandler.handshakeFuture();
                        handshakeDone.addListener(new GenericFutureListener<Future<? super Channel>>() {
                            @Override
                            public void operationComplete(Future<? super Channel> future) throws Exception {
                                authenticate();
                            }
                        });
                        p.addLast(sslHandler);
                    }
                    // decoder
                    p.addLast(new DelimiterBasedFrameDecoder(102400, Delimiters.lineDelimiter()));
                    p.addLast(new StringDecoder(Charset.forName("UTF-8")));

                    //encoder
                    p.addLast(new StringEncoder(Charset.forName("UTF-8")));
                    p.addLast(NewsChannel.this);
                }
            });
    // Bind and start to accept incoming connections.
    mChannel = b.connect(mHost, mPort).channel();
}

From source file:com.mpcc.springmvc.configuration.ServerInitializer.java

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerProtocolHandler("/websocket"));
    pipeline.addLast(new ServerHandler());

}

From source file:com.mpush.client.gateway.GatewayClient.java

License:Apache License

@Override
protected void initPipeline(ChannelPipeline pipeline) {
    super.initPipeline(pipeline);
    if (trafficShapingHandler != null) {
        pipeline.addLast(trafficShapingHandler);
    }/*from   w ww .j  a  va  2 s .  co m*/
}

From source file:com.mpush.core.server.AdminServer.java

License:Apache License

@Override
protected void initPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    super.initPipeline(pipeline);
}

From source file:com.mpush.core.server.WebSocketServer.java

License:Apache License

@Override
protected void initPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(CC.mp.net.ws_path, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler());
    pipeline.addLast(getChannelHandler());
}