org.jboss.netty.channel.ChannelPipeline Java Examples
The following examples show how to use
org.jboss.netty.channel.ChannelPipeline.
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 File: ShuffleHandler.java From tez with 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 #2
Source File: NettyTransport.java From Elasticsearch with 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 #3
Source File: NettyClient.java From dubbox with 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 #4
Source File: NettyTransport.java From Elasticsearch with 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 #5
Source File: BgpControllerImplTest.java From onos with 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 #6
Source File: HttpServer.java From feeyo-hlsserver with 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 #7
Source File: FrameDecoder.java From android-netty with 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 #8
Source File: UdpServer.java From feeyo-hlsserver with 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 #9
Source File: SyslogTcpSource.java From mt-flume with 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 #10
Source File: HttpDataServerPipelineFactory.java From incubator-tajo with 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 #11
Source File: ControllerConnector.java From FlowSpaceFirewall with 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 #12
Source File: NettyClient.java From dubbox-hystrix with 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 #13
Source File: OpenflowPipelineFactory.java From floodlight_with_topoguard with 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 #14
Source File: Bootstrap.java From android-netty with 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 #15
Source File: NettyClient.java From dubbo-2.6.5 with 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 #16
Source File: WebSocketServerPipelineFactory.java From usergrid with 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 #17
Source File: HttpServerPipelineFactory.java From restcommander with 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 #18
Source File: NettyClient.java From dubbox with 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 #19
Source File: BgpControllerImplTest.java From onos with 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 #20
Source File: TestAvroSource.java From mt-flume with 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 #21
Source File: ShuffleHandler.java From big-c with 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 #22
Source File: RPCPipelineFactory.java From floodlight_with_topoguard with 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 #23
Source File: HttpOutboundPipeline.java From zuul-netty with 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 #24
Source File: AvroSource.java From mt-flume with 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 #25
Source File: FakeCarbonPipelineFactory.java From vmstats with Apache License 2.0 | 5 votes |
public ChannelPipeline getPipeline() throws Exception { // this is pretty verbose from the netty examples ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast("decoder", new StringDecoder()); pipeline.addLast("encoder", new StringEncoder()); pipeline.addLast("handler", new FakeCarbonHandler(appConfig)); return pipeline; }
Example #26
Source File: ShuffleHandler.java From tez with Apache License 2.0 | 5 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); 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 #27
Source File: MemcachedPipelineFactory.java From fqueue with Apache License 2.0 | 5 votes |
public final ChannelPipeline getPipeline() throws Exception { SessionStatus status = new SessionStatus().ready(); return Channels.pipeline(new MemcachedFrameDecoder(status, frameSize), new MemcachedCommandDecoder(status), memcachedCommandHandler, memcachedResponseEncoder); }
Example #28
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Override public SocketChannel newChannel(ChannelPipeline pipeline) { try { ZlibEncoder encoder = new ZlibEncoder(compressionLevel); pipeline.addFirst("deflater", encoder); pipeline.addFirst("inflater", new ZlibDecoder()); return super.newChannel(pipeline); } catch (Exception ex) { throw new RuntimeException("Cannot create Compression channel", ex); } }
Example #29
Source File: NetworkFailuresProxy.java From flink with Apache License 2.0 | 5 votes |
public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }
Example #30
Source File: UdpWorker.java From parallec with Apache License 2.0 | 5 votes |
@Override public ChannelPipeline getPipeline() { // cannot have the DelimiterBasedFrameDecoder! does not work with // UDP; make packet missing. ChannelPipeline pipeline = Channels.pipeline(); // ORDER matters!!! put the channdler first pipeline.addLast("idleTimer", idleStateHandler); pipeline.addLast("idleHandler", myIdleHandler); pipeline.addLast("stringDecoder", UdpMeta.stringDecoder); pipeline.addLast("stringEncoder", UdpMeta.stringEncoder); pipeline.addLast("UDPUpstreamHandler", new UdpChannelHandler( udpWorker)); return pipeline; }