List of usage examples for io.netty.channel ChannelPipeline addLast
ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);
From source file:com.andrewkroh.cisco.xmlservices.HttpTestServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("aggregator", new HttpObjectAggregator(1048576)); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("handler", handler); }
From source file:com.athena.dolly.websocket.client.test.WebSocketClient.java
License:Apache License
private void initialize() throws InterruptedException { group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); String protocol = uri.getScheme(); if (!"ws".equals(protocol)) { throw new IllegalArgumentException("Unsupported protocol: " + protocol); }/*ww w . ja v a 2 s .c om*/ HttpHeaders customHeaders = new DefaultHttpHeaders(); customHeaders.add("MyHeader", "MyValue"); // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. // If you change it to V00, ping is not supported and remember to change // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. final WebSocketClientHandler handler = new WebSocketClientHandler(WebSocketClientHandshakerFactory .newHandshaker(uri, WebSocketVersion.V13, null, false, customHeaders)); bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-codec", new HttpClientCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(8192)); pipeline.addLast("ws-handler", handler); } }); System.out.println("WebSocket Client connecting"); ch = bootstrap.connect(uri.getHost(), uri.getPort()).sync().channel(); handler.handshakeFuture().sync(); }
From source file:com.athena.dolly.websocket.server.test.WebSocketServerInitializer.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)); pipeline.addLast("handler", new WebSocketServerHandler()); }
From source file:com.athena.dolly.websocket.server.test.WebSocketSslServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); SSLEngine engine = WebSocketSslServerSslContext.getInstance().serverContext().createSSLEngine(); engine.setUseClientMode(false);/*from w ww. ja v a 2s. c o m*/ pipeline.addLast("ssl", new SslHandler(engine)); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("handler", new WebSocketSslServerHandler()); }
From source file:com.athena.meerkat.agent.netty.MeerkatClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. LOGGER.debug("**************************Tran - Init *****************************"); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null))); pipeline.addLast("encoder", new ObjectEncoder()); pipeline.addLast("handler", handler); }
From source file:com.athena.peacock.agent.netty.PeacockClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null))); pipeline.addLast("encoder", new ObjectEncoder()); pipeline.addLast("handler", handler); }
From source file:com.athena.peacock.controller.netty.PeacockServerInitializer.java
License:Open Source License
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null))); pipeline.addLast("encoder", new ObjectEncoder()); pipeline.addLast("handler", new PeacockServerHandler()); }
From source file:com.baidu.jprotobuf.pbrpc.transport.RpcClientPipelineinitializer.java
License:Apache License
/** * @brief ??/* www . j a v a 2 s . c om*/ * @return ChannelPipeline * @throws Exception * @author songhuiqing * @date 2013/03/07 11:14:53 */ @Override protected void initChannel(Channel ch) throws Exception { LOG.log(Level.FINEST, "begin process RPC server response to client handler"); ChannelPipeline channelPipe = ch.pipeline(); int idleTimeout = this.rpcClient.getRpcClientOptions().getIdleTimeout(); channelPipe.addFirst(RPC_CHANNEL_STATE_AWARE_HANDLER, new IdleStateHandler(idleTimeout, idleTimeout, idleTimeout)); channelPipe.addFirst(RPC_CHANNEL_IDLE_HANDLER, new RpcServerChannelIdleHandler()); // check if need to compress for data and attachment channelPipe.addFirst(COMPRESS, new RpcDataPackageCompressHandler()); // encode RpcDataPackage to byte array channelPipe.addFirst(CLIENT_ENCODER, new RpcDataPackageEncoder(rpcClient.getRpcClientOptions().getChunkSize())); // receive data from server // receive byte array to encode to RpcDataPackage channelPipe.addLast(CLIENT_DECODER, new RpcDataPackageDecoder(-1)); // do uncompress handle channelPipe.addLast(UNCOMPRESS, new RpcDataPackageUnCompressHandler()); // do client handler channelPipe.addLast(CLIENT_HANDLER, new RpcClientServiceHandler(rpcClient)); }
From source file:com.baidu.jprotobuf.pbrpc.transport.RpcServerPipelineInitializer.java
License:Apache License
@Override protected void initChannel(Channel ch) throws Exception { LOG.log(Level.FINE, "begin process RPC server handler"); ChannelPipeline channelPipe = ch.pipeline(); // receive request data channelPipe.addLast(RPC_CHANNEL_STATE_AWARE_HANDLER, new IdleStateHandler(this.rpcServerOptions.getKeepAliveTime(), this.rpcServerOptions.getKeepAliveTime(), this.rpcServerOptions.getKeepAliveTime())); channelPipe.addLast(RPC_CHANNEL_IDLE_HANDLER, new RpcServerChannelIdleHandler()); RpcDataPackageDecoder rpcDataPackageDecoder = new RpcDataPackageDecoder( this.rpcServerOptions.getChunkPackageTimeout()); rpcDataPackageDecoderList.add(rpcDataPackageDecoder); // receive byte array to encode to RpcDataPackage channelPipe.addLast(DECODER, rpcDataPackageDecoder); // do uncompress handle channelPipe.addLast(UNCOMPRESS, new RpcDataPackageUnCompressHandler()); // to process RPC service handler of request object RpcDataPackage and // return new RpcDataPackage channelPipe.addLast(RPC_SERVER_HANDLER, new RpcServiceHandler(this.rpcServiceRegistry)); // response back // check if need to compress for data and attachment channelPipe.addFirst(COMPRESS, new RpcDataPackageCompressHandler()); // encode RpcDataPackage to byte array channelPipe.addFirst(SERVER_DATA_PACK, new RpcDataPackageEncoder()); }
From source file:com.baidu.rigel.biplatform.tesseract.node.service.IndexAndSearchClient.java
License:Open Source License
public IndexAndSearchClient() { // channelMaps = new ConcurrentHashMap<NodeAddress, Channel>(); actionHandlerMaps = new ConcurrentHashMap<String, ChannelHandler>(); b = new Bootstrap(); group = new NioEventLoopGroup(); b.group(group);/*from w w w .j av a 2s . c o m*/ b.channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000); b.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("encode", new ObjectEncoder()); pipeline.addLast("decode", new ObjectDecoder(ClassResolvers.weakCachingConcurrentResolver(null))); // pipeline.addLast("frameencoder",new LengthFieldPrepender(4,false)); // pipeline.addLast("framedecoder",new LengthFieldBasedFrameDecoder(1024*1024*1024, 0, 4,0,4)); } }); logger.info("IndexAndSearchClient init finished"); }