Java Code Examples for org.jboss.netty.channel.ChannelPipeline
The following examples show how to use
org.jboss.netty.channel.ChannelPipeline.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: dubbo-2.6.5 Author: tianheframe File: NettyClient.java License: Apache License 2.0 | 6 votes |
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getConnectTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
Example #2
Source Project: android-netty Author: urunimi File: Bootstrap.java License: Apache License 2.0 | 6 votes |
/** * Dependency injection friendly convenience method for * {@link #setPipeline(ChannelPipeline)} which sets the default pipeline of * this bootstrap from an ordered map. * <p> * Please note that this method is a convenience method that works only * when <b>1)</b> you create only one channel from this bootstrap (e.g. * one-time client-side or connectionless channel) or <b>2)</b> all handlers * in the pipeline is stateless. You have to use * {@link #setPipelineFactory(ChannelPipelineFactory)} if <b>1)</b> your * pipeline contains a stateful {@link ChannelHandler} and <b>2)</b> one or * more channels are going to be created by this bootstrap (e.g. server-side * channels). * * @throws IllegalArgumentException * if the specified map is not an ordered map */ public void setPipelineAsMap(Map<String, ChannelHandler> pipelineMap) { if (pipelineMap == null) { throw new NullPointerException("pipelineMap"); } if (!isOrderedMap(pipelineMap)) { throw new IllegalArgumentException( "pipelineMap is not an ordered map. " + "Please use " + LinkedHashMap.class.getName() + '.'); } ChannelPipeline pipeline = pipeline(); for (Map.Entry<String, ChannelHandler> e: pipelineMap.entrySet()) { pipeline.addLast(e.getKey(), e.getValue()); } setPipeline(pipeline); }
Example #3
Source Project: feeyo-hlsserver Author: variflight File: UdpServer.java License: Apache License 2.0 | 6 votes |
public void startup(int port) { ChannelFactory channelFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool()); bootstrap = new ConnectionlessBootstrap( channelFactory ); bootstrap.setOption("reuseAddress", false); bootstrap.setOption("child.reuseAddress", false); bootstrap.setOption("readBufferSize", 1024 * 1024 * 15); //15M bootstrap.setOption("writeBufferSize", 1024 * 20); bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(1024 * 3)); bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(1024 * 3)); bootstrap.setPipelineFactory( new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("handler", new UdpServerChannelHandler()); return pipeline; } }); datagramChannel = (DatagramChannel) bootstrap.bind( new InetSocketAddress( port ) ); }
Example #4
Source Project: feeyo-hlsserver Author: variflight File: HttpServer.java License: Apache License 2.0 | 6 votes |
public void startup(int port) { final int maxContentLength = 1024 * 1024 * 1024; bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(bossExecutor, workerExecutor)); bootstrap.setOption("connectTimeoutMillis", 10000); bootstrap.setOption("reuseAddress", true); // kernel optimization bootstrap.setOption("keepAlive", true); // for mobiles & our bootstrap.setOption("tcpNoDelay", true); // better latency over bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline p = Channels.pipeline(); p.addLast("http-encoder", new HttpResponseEncoder()); p.addLast("http-decoder", new HttpRequestDecoder()); p.addLast("http-aggregator", new HttpChunkAggregator( maxContentLength )); p.addLast("server-handler", new HttpServerRequestHandler()); return p; } }); channel = bootstrap.bind(new InetSocketAddress(port)); }
Example #5
Source Project: Elasticsearch Author: baidu File: NettyTransport.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline channelPipeline = Channels.pipeline(); SizeHeaderFrameDecoder sizeHeader = new SizeHeaderFrameDecoder(); if (nettyTransport.maxCumulationBufferCapacity != null) { if (nettyTransport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) { sizeHeader.setMaxCumulationBufferCapacity(Integer.MAX_VALUE); } else { sizeHeader.setMaxCumulationBufferCapacity((int) nettyTransport.maxCumulationBufferCapacity.bytes()); } } if (nettyTransport.maxCompositeBufferComponents != -1) { sizeHeader.setMaxCumulationBufferComponents(nettyTransport.maxCompositeBufferComponents); } channelPipeline.addLast("size", sizeHeader); // using a dot as a prefix means, this cannot come from any settings parsed channelPipeline.addLast("dispatcher", new MessageChannelHandler(nettyTransport, nettyTransport.logger, ".client")); return channelPipeline; }
Example #6
Source Project: Elasticsearch Author: baidu File: NettyTransport.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline channelPipeline = Channels.pipeline(); channelPipeline.addLast("openChannels", nettyTransport.serverOpenChannels); SizeHeaderFrameDecoder sizeHeader = new SizeHeaderFrameDecoder(); if (nettyTransport.maxCumulationBufferCapacity != null) { if (nettyTransport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) { sizeHeader.setMaxCumulationBufferCapacity(Integer.MAX_VALUE); } else { sizeHeader.setMaxCumulationBufferCapacity((int) nettyTransport.maxCumulationBufferCapacity.bytes()); } } if (nettyTransport.maxCompositeBufferComponents != -1) { sizeHeader.setMaxCumulationBufferComponents(nettyTransport.maxCompositeBufferComponents); } channelPipeline.addLast("size", sizeHeader); channelPipeline.addLast("dispatcher", new MessageChannelHandler(nettyTransport, nettyTransport.logger, name)); return channelPipeline; }
Example #7
Source Project: dubbox Author: learningtcc File: NettyClient.java License: Apache License 2.0 | 6 votes |
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
Example #8
Source Project: mt-flume Author: javachen File: SyslogTcpSource.java License: Apache License 2.0 | 6 votes |
@Override public void start() { ChannelFactory factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ServerBootstrap serverBootstrap = new ServerBootstrap(factory); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { syslogTcpHandler handler = new syslogTcpHandler(); handler.setEventSize(eventSize); handler.setFormater(formaterProp); return Channels.pipeline(handler); } }); logger.info("Syslog TCP Source starting..."); if (host == null) { nettyChannel = serverBootstrap.bind(new InetSocketAddress(port)); } else { nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port)); } super.start(); }
Example #9
Source Project: FlowSpaceFirewall Author: GlobalNOC File: ControllerConnector.java License: Apache License 2.0 | 6 votes |
/** * creates a new pipeline for interacting with the * controller. This is where the controllerHandler and * the timeouthandler come into play * @return the pipeline (ChannelPipeline) for a new Socket. */ private ChannelPipeline getPipeline(){ ChannelPipeline pipe = Channels.pipeline(); ChannelHandler idleHandler = new IdleStateHandler(timer, 20, 25, 0); ChannelHandler readTimeoutHandler = new ReadTimeoutHandler(timer, 30); OFControllerChannelHandler controllerHandler = new OFControllerChannelHandler(); pipe.addLast("ofmessagedecoder", new OFMessageDecoder()); pipe.addLast("ofmessageencoder", new OFMessageEncoder()); pipe.addLast("idle", idleHandler); pipe.addLast("timeout", readTimeoutHandler); pipe.addLast("handshaketimeout", new ControllerHandshakeTimeoutHandler(controllerHandler, timer, 15)); pipe.addLast("handler", controllerHandler); return pipe; }
Example #10
Source Project: dubbox-hystrix Author: yunhaibin File: NettyClient.java License: Apache License 2.0 | 6 votes |
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
Example #11
Source Project: zuul-netty Author: neilbeveridge File: HttpOutboundPipeline.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = pipeline(); pipeline.addLast("idle-detection", IDLE_STATE_HANDLER); pipeline.addLast("logging", new LoggingHandler(InternalLogLevel.DEBUG)); pipeline.addLast("http-deflater", new HttpContentCompressor()); pipeline.addLast("decoder", new HttpResponseDecoder(RESPONSE_MAX_INITIAL_LINE_LENGTH, RESPONSE_MAX_HEADER_SIZE, RESPONSE_MAX_CHUNK_SIZE)); pipeline.addLast("encoder", new HttpRequestEncoder()); pipeline.addLast("http-inflater", new HttpContentDecompressor()); pipeline.addLast("remote-hop-timer", new ClientTimingHandler("outbound")); pipeline.addLast("exception-surfacer", EXCEPTION_SURFACER); pipeline.addLast("idle-watchdog", new IdleChannelWatchdog("outbound")); return pipeline; }
Example #12
Source Project: big-c Author: yncxcw File: ShuffleHandler.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); if (sslFactory != null) { pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine())); } pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("chunking", new ChunkedWriteHandler()); pipeline.addLast("shuffle", SHUFFLE); return pipeline; // TODO factor security manager into pipeline // TODO factor out encode/decode to permit binary shuffle // TODO factor out decode of index to permit alt. models }
Example #13
Source Project: mt-flume Author: javachen File: TestAvroSource.java License: Apache License 2.0 | 6 votes |
@Override public SocketChannel newChannel(ChannelPipeline pipeline) { try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[]{new PermissiveTrustManager()}, null); SSLEngine sslEngine = sslContext.createSSLEngine(); sslEngine.setUseClientMode(true); // addFirst() will make SSL handling the first stage of decoding // and the last stage of encoding pipeline.addFirst("ssl", new SslHandler(sslEngine)); return super.newChannel(pipeline); } catch (Exception ex) { throw new RuntimeException("Cannot create SSL channel", ex); } }
Example #14
Source Project: onos Author: opennetworkinglab File: BgpControllerImplTest.java License: Apache License 2.0 | 6 votes |
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress) throws InterruptedException { ChannelFactory channelFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ChannelPipelineFactory pipelineFactory = () -> { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("BgpPeerFrameDecoderTest", peerFrameDecoder); pipeline.addLast("BgpPeerChannelHandlerTest", peerChannelHandler); return pipeline; }; peerBootstrap = new ClientBootstrap(channelFactory); peerBootstrap.setOption("child.keepAlive", true); peerBootstrap.setOption("child.tcpNoDelay", true); peerBootstrap.setPipelineFactory(pipelineFactory); Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel(); return channel; }
Example #15
Source Project: dubbox Author: hutai123 File: NettyClient.java License: Apache License 2.0 | 6 votes |
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
Example #16
Source Project: restcommander Author: eBay File: HttpServerPipelineFactory.java License: Apache License 2.0 | 6 votes |
public ChannelPipeline getPipeline() throws Exception { Integer max = Integer.valueOf(Play.configuration.getProperty("play.netty.maxContentLength", "-1")); ChannelPipeline pipeline = pipeline(); PlayHandler playHandler = new PlayHandler(); pipeline.addLast("flashPolicy", new FlashPolicyHandler()); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new StreamChunkAggregator(max)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("chunkedWriter", playHandler.chunkedWriteHandler); pipeline.addLast("handler", playHandler); return pipeline; }
Example #17
Source Project: tez Author: apache File: ShuffleHandler.java License: Apache License 2.0 | 6 votes |
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { future.getChannel().close(); return; } int waitCount = this.reduceContext.getMapsToWait().decrementAndGet(); if (waitCount == 0) { metrics.operationComplete(future); // Let the idle timer handler close keep-alive connections if (reduceContext.getKeepAlive()) { ChannelPipeline pipeline = future.getChannel().getPipeline(); TimeoutHandler timeoutHandler = (TimeoutHandler) pipeline.get(TIMEOUT_HANDLER); timeoutHandler.setEnabledTimeout(true); } else { future.getChannel().close(); } } else { pipelineFact.getSHUFFLE().sendMap(reduceContext); } }
Example #18
Source Project: usergrid Author: apache File: WebSocketServerPipelineFactory.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = pipeline(); if ( ssl ) { SSLEngine sslEngine = WebSocketSslContextFactory.getServerContext().createSSLEngine(); sslEngine.setUseClientMode( false ); pipeline.addLast( "ssl", new SslHandler( sslEngine ) ); } pipeline.addLast( "decoder", new HttpRequestDecoder() ); pipeline.addLast( "aggregator", new HttpChunkAggregator( 65536 ) ); pipeline.addLast( "encoder", new HttpResponseEncoder() ); pipeline.addLast( "execution", executionHandler ); pipeline.addLast( "handler", new WebSocketChannelHandler( emf, smf, management, securityManager, ssl ) ); return pipeline; }
Example #19
Source Project: floodlight_with_topoguard Author: xuraylei File: RPCPipelineFactory.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { RPCChannelHandler channelHandler = new RPCChannelHandler(syncManager, rpcService); IdleStateHandler idleHandler = new IdleStateHandler(timer, 5, 10, 0); ReadTimeoutHandler readTimeoutHandler = new ReadTimeoutHandler(timer, 30); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("idle", idleHandler); pipeline.addLast("timeout", readTimeoutHandler); pipeline.addLast("handshaketimeout", new HandshakeTimeoutHandler(channelHandler, timer, 10)); pipeline.addLast("frameDecoder", new ThriftFrameDecoder(maxFrameSize)); pipeline.addLast("frameEncoder", new ThriftFrameEncoder()); pipeline.addLast("handler", channelHandler); return pipeline; }
Example #20
Source Project: floodlight_with_topoguard Author: xuraylei File: OpenflowPipelineFactory.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { OFChannelHandler handler = new OFChannelHandler(controller); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("ofmessagedecoder", new OFMessageDecoder()); pipeline.addLast("ofmessageencoder", new OFMessageEncoder()); pipeline.addLast("idle", idleHandler); pipeline.addLast("timeout", readTimeoutHandler); pipeline.addLast("handshaketimeout", new HandshakeTimeoutHandler(handler, timer, 15)); if (pipelineExecutor != null) pipeline.addLast("pipelineExecutor", new ExecutionHandler(pipelineExecutor)); pipeline.addLast("handler", handler); return pipeline; }
Example #21
Source Project: mt-flume Author: javachen File: AvroSource.java License: Apache License 2.0 | 6 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); if (enableCompression) { ZlibEncoder encoder = new ZlibEncoder(6); pipeline.addFirst("deflater", encoder); pipeline.addFirst("inflater", new ZlibDecoder()); } if (enableSsl) { SSLEngine sslEngine = createServerSSLContext().createSSLEngine(); sslEngine.setUseClientMode(false); // addFirst() will make SSL handling the first stage of decoding // and the last stage of encoding this must be added after // adding compression handling above pipeline.addFirst("ssl", new SslHandler(sslEngine)); } return pipeline; }
Example #22
Source Project: incubator-tajo Author: apache File: HttpDataServerPipelineFactory.java License: Apache License 2.0 | 6 votes |
public ChannelPipeline getPipeline() throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = pipeline(); // Uncomment the following line if you want HTTPS // SSLEngine engine = // SecureChatSslContextFactory.getServerContext().createSSLEngine(); // engine.setUseClientMode(false); // pipeline.addLast("ssl", new SslHandler(engine)); pipeline.addLast("decoder", new HttpRequestDecoder()); //pipeline.addLast("aggregator", new HttpChunkAggregator(65536)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("deflater", new HttpContentCompressor()); pipeline.addLast("handler", new HttpDataServerHandler(userName, appId)); return pipeline; }
Example #23
Source Project: onos Author: opennetworkinglab File: BgpControllerImplTest.java License: Apache License 2.0 | 6 votes |
/** * Starts the BGP peer. * * @param connectToSocket the socket to connect to */ private void connect(InetSocketAddress connectToSocket) throws InterruptedException { ChannelFactory channelFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ChannelPipelineFactory pipelineFactory = () -> { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("BgpPeerFrameDecoderTest", peerFrameDecoder); pipeline.addLast("BgpPeerChannelHandlerTest", peerChannelHandler); return pipeline; }; peerBootstrap = new ClientBootstrap(channelFactory); peerBootstrap.setOption("child.keepAlive", true); peerBootstrap.setOption("child.tcpNoDelay", true); peerBootstrap.setPipelineFactory(pipelineFactory); peerBootstrap.connect(connectToSocket); }
Example #24
Source Project: android-netty Author: urunimi File: FrameDecoder.java License: Apache License 2.0 | 6 votes |
/** * Replace this {@link FrameDecoder} in the {@link ChannelPipeline} with the * given {@link ChannelHandler}. All remaining bytes in the * {@link ChannelBuffer} will get send to the new {@link ChannelHandler} * that was used as replacement * */ public void replace(String handlerName, ChannelHandler handler) { if (ctx == null) { throw new IllegalStateException("Replace cann only be called once the FrameDecoder is added to the ChannelPipeline"); } ChannelPipeline pipeline = ctx.getPipeline(); pipeline.addAfter(ctx.getName(), handlerName, handler); try { if (cumulation != null) { Channels.fireMessageReceived(ctx, cumulation.readBytes(actualReadableBytes())); } } finally { pipeline.remove(this); } }
Example #25
Source Project: android-netty Author: urunimi File: AbstractNioChannelSink.java License: Apache License 2.0 | 5 votes |
@Override public ChannelFuture execute(ChannelPipeline pipeline, final Runnable task) { Channel ch = pipeline.getChannel(); if (ch instanceof AbstractNioChannel<?>) { AbstractNioChannel<?> channel = (AbstractNioChannel<?>) ch; ChannelRunnableWrapper wrapper = new ChannelRunnableWrapper(pipeline.getChannel(), task); channel.worker.executeInIoThread(wrapper); return wrapper; } return super.execute(pipeline, task); }
Example #26
Source Project: aion-germany Author: AionGermany File: LoginToClientPipeLineFactory.java License: GNU General Public License v3.0 | 5 votes |
/** * Decoding process will include the following handlers: - framedecoder - * packetdecoder - handler Encoding process: - packetencoder Please note the * sequence of handlers */ @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("framedecoder", new PacketFrameDecoder()); pipeline.addLast("packetdecoder", new LoginPacketDecoder()); pipeline.addLast("packetencoder", new LoginPacketEncoder()); pipeline.addLast("executor", executionHandler); pipeline.addLast("handler", new ClientChannelHandler(clientPacketHandler)); return pipeline; }
Example #27
Source Project: onos Author: opennetworkinglab File: BgpSessionManager.java License: Apache License 2.0 | 5 votes |
public void start() { log.debug("BGP Session Manager start."); isShutdown = false; ChannelFactory channelFactory = new NioServerSocketChannelFactory( newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d", log)), newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d", log))); ChannelPipelineFactory pipelineFactory = () -> { // Allocate a new session per connection BgpSession bgpSessionHandler = new BgpSession(BgpSessionManager.this); BgpFrameDecoder bgpFrameDecoder = new BgpFrameDecoder(bgpSessionHandler); // Setup the processing pipeline ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder); pipeline.addLast("BgpSession", bgpSessionHandler); return pipeline; }; InetSocketAddress listenAddress = new InetSocketAddress(bgpPort); serverBootstrap = new ServerBootstrap(channelFactory); // serverBootstrap.setOptions("reuseAddr", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setPipelineFactory(pipelineFactory); try { serverChannel = serverBootstrap.bind(listenAddress); allChannels.add(serverChannel); } catch (ChannelException e) { log.debug("Exception binding to BGP port {}: ", listenAddress.getPort(), e); } }
Example #28
Source Project: voyage Author: zhaoshiling1017 File: NettyRpcConnection.java License: Apache License 2.0 | 5 votes |
/** * @param connectStatus 心跳检测状态是否正常 * @throws Throwable */ public void open(boolean connectStatus) throws Throwable { logger.info("open start,"+getConnStr()); bootstrap = new ClientBootstrap(factory); // timer = new HashedWheelTimer(); { bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(clientConfig.getTcpNoDelay())); bootstrap.setOption("reuseAddress", Boolean.parseBoolean(clientConfig.getReuseAddress())); bootstrap.setOption("SO_RCVBUF",1024*128); bootstrap.setOption("SO_SNDBUF",1024*128); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { ChannelPipeline pipeline = Channels.pipeline(); // int readTimeout = clientConfig.getReadTimeout(); // if (readTimeout > 0) { // pipeline.addLast("timeout", new ReadTimeoutHandler(timer, // readTimeout, TimeUnit.MILLISECONDS)); // } pipeline.addLast("encoder", new RpcRequestEncode()); pipeline.addLast("decoder", new RpcResponseDecode()); pipeline.addLast("handler", NettyRpcConnection.this); return pipeline; } }); } connected.set(connectStatus); logger.info("open finish,"+getConnStr()); }
Example #29
Source Project: jstorm Author: alibaba File: StormServerPipelineFactory.java License: Apache License 2.0 | 5 votes |
public ChannelPipeline getPipeline() throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = Channels.pipeline(); // Decoder pipeline.addLast("decoder", new MessageDecoder(true, conf)); // Encoder pipeline.addLast("encoder", new MessageEncoder()); // business logic. pipeline.addLast("handler", new StormServerHandler(server)); return pipeline; }
Example #30
Source Project: glowroot Author: glowroot File: HttpServer.java License: Apache License 2.0 | 5 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("deflater", new HttpContentCompressor()); pipeline.addLast("handler", new HttpServerHandler()); return pipeline; }