List of usage examples for io.netty.channel ChannelPipeline addLast
ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);
From source file:com.hop.hhxx.example.spdy.client.SpdyClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc())); pipeline.addLast("spdyFrameCodec", new SpdyFrameCodec(SPDY_3_1)); pipeline.addLast("spdyFrameLogger", new io.netty.example.spdy.client.SpdyFrameLogger(INFO)); pipeline.addLast("spdySessionHandler", new SpdySessionHandler(SPDY_3_1, false)); pipeline.addLast("spdyHttpEncoder", new SpdyHttpEncoder(SPDY_3_1)); pipeline.addLast("spdyHttpDecoder", new SpdyHttpDecoder(SPDY_3_1, MAX_SPDY_CONTENT_LENGTH)); pipeline.addLast("spdyStreamIdHandler", new SpdyClientStreamIdHandler()); pipeline.addLast("httpHandler", httpResponseHandler); }
From source file:com.hxr.javatone.concurrency.netty.official.factorial.FactorialClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Enable stream compression (you can remove these two if unnecessary) pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP)); pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP)); // Add the number codec first, pipeline.addLast("decoder", new BigIntegerDecoder()); pipeline.addLast("encoder", new NumberEncoder()); // and then business logic. pipeline.addLast("handler", new FactorialClientHandler(count)); }
From source file:com.hxr.javatone.concurrency.netty.official.factorial.FactorialServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Enable stream compression (you can remove these two if unnecessary) pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP)); pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP)); // Add the number codec first, pipeline.addLast("decoder", new BigIntegerDecoder()); pipeline.addLast("encoder", new NumberEncoder()); // and then business logic. // Please note we create a handler for every new channel // because it has stateful properties. pipeline.addLast("handler", new FactorialServerHandler()); }
From source file:com.hxr.javatone.concurrency.netty.official.securechat.SecureChatClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine(); engine.setUseClientMode(true);// w w w . ja v a 2 s . co m pipeline.addLast("ssl", new SslHandler(engine)); // On top of the SSL handler, add the text line codec. pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast("decoder", new StringDecoder()); pipeline.addLast("encoder", new StringEncoder()); // and then business logic. pipeline.addLast("handler", new SecureChatClientHandler()); }
From source file:com.hxr.javatone.concurrency.netty.official.securechat.SecureChatServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. ////from ww w. j a v a 2s . c om // Read SecureChatSslContextFactory // if you need client certificate authentication. SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine(); engine.setUseClientMode(false); pipeline.addLast("ssl", new SslHandler(engine)); // On top of the SSL handler, add the text line codec. pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast("decoder", new StringDecoder()); pipeline.addLast("encoder", new StringEncoder()); // and then business logic. pipeline.addLast("handler", new SecureChatServerHandler()); }
From source file:com.hzmsc.scada.Jmtis.server.PortUnificationServerHandler.java
License:Apache License
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("deflater", new HttpContentCompressor()); p.addLast("handler", new HttpHelloWorldServerHandler()); p.remove(this); }
From source file:com.hzq.nio.websocket.WebSocketServer.java
License:Apache License
public void run(int port) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from www. j av a 2s . c om ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-codec", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); pipeline.addLast("handler", new WebSocketServerHandler()); } }); Channel ch = b.bind(port).sync().channel(); System.out.println("Web socket server started at port " + port + '.'); System.out.println("Open your browser and navigate to http://localhost:" + port + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.im.socket.netty.tcp.SocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel sh) throws Exception { ChannelPipeline pipeline = sh.pipeline(); pipeline.addLast("coder", new StringServerCodec()); pipeline.addLast("handler", new SocketHandler()); }
From source file:com.imaginarycode.minecraft.bungeejson.impl.httpserver.NettyBootstrap.java
License:Open Source License
public void initialize() { group = new NioEventLoopGroup(5, factory); int port = 7432; // CONFIG ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childHandler(new ChannelInitializer<SocketChannel>() { @Override//w w w .java 2 s.c o m public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("messageCodec", new HttpServerCodec()); pipeline.addLast("messageHandler", new HttpServerHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); channelFuture = b.bind(port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { BungeeJSONPlugin.getPlugin().getLogger() .info("BungeeJSON server started on " + channelFuture.channel().localAddress()); } }); }
From source file:com.informatica.surf.sources.http.HttpServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); // TODO: make this same as block size pipeline.addLast("handler", new HttpServerHandler(_ppaths, _wpaths, _messageQueue)); }