@Override protected void initChannel(SocketChannel ch) throws Exception { // logger.debug("initializing client connection."); connection = initRemoteConnection(ch); ch.closeFuture().addListener(getCloseHandler(ch, connection)); final ChannelPipeline pipe = ch.pipeline(); // Make sure that the SSL handler is the first handler in the pipeline so everything is encrypted if (isSslEnabled()) { setupSSL(pipe, sslHandshakeListener); } pipe.addLast(RpcConstants.PROTOCOL_DECODER, getDecoder(connection.getAllocator())); pipe.addLast(RpcConstants.MESSAGE_DECODER, new RpcDecoder("c-" + rpcConfig.getName())); pipe.addLast(RpcConstants.PROTOCOL_ENCODER, new RpcEncoder("c-" + rpcConfig.getName())); pipe.addLast(RpcConstants.HANDSHAKE_HANDLER, new ClientHandshakeHandler(connection)); if(pingHandler != null){ pipe.addLast(RpcConstants.IDLE_STATE_HANDLER, pingHandler); } pipe.addLast(RpcConstants.MESSAGE_HANDLER, new InboundHandler(connection)); pipe.addLast(RpcConstants.EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); } }); //
@Override protected void initChannel(SocketChannel ch) throws Exception { // logger.debug("Starting initialization of server connection."); SC connection = initRemoteConnection(ch); ch.closeFuture().addListener(getCloseHandler(ch, connection)); final ChannelPipeline pipe = ch.pipeline(); // Make sure that the SSL handler is the first handler in the pipeline so everything is encrypted if (isSslEnabled()) { setupSSL(pipe); } pipe.addLast(RpcConstants.PROTOCOL_DECODER, getDecoder(connection.getAllocator(), getOutOfMemoryHandler())); pipe.addLast(RpcConstants.MESSAGE_DECODER, new RpcDecoder("s-" + rpcConfig.getName())); pipe.addLast(RpcConstants.PROTOCOL_ENCODER, new RpcEncoder("s-" + rpcConfig.getName())); pipe.addLast(RpcConstants.HANDSHAKE_HANDLER, getHandshakeHandler(connection)); if (rpcMapping.hasTimeout()) { pipe.addLast(RpcConstants.TIMEOUT_HANDLER, new LoggingReadTimeoutHandler(connection, rpcMapping.getTimeout())); } pipe.addLast(RpcConstants.MESSAGE_HANDLER, new InboundHandler(connection)); pipe.addLast(RpcConstants.EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); connect = true; // logger.debug("Server connection initialization completed."); } });
public void setChannelCloseHandler(ChannelFutureListener closeHandler) { channel.closeFuture().addListener(closeHandler); }
@Override public ConsumerSpec close(final Runnable onClose) { channel.closeFuture().addListener(new ChannelCloseListener(onClose)); return this; }
@Override public void addTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) { getChannel().closeFuture().addListener(listener); }
@Override public ConsumerSpec writeIdle(long idleTimeout, final Runnable onWriteIdle) { final IdleWriteListener iwl = new IdleWriteListener(idleTimeout, onWriteIdle); channel.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { try { iwl.channelInactive(null); } catch(NullPointerException ignored) {} } }); channel.pipeline().addLast(iwl); return this; } }
@Override protected void initChannel(final SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (log.isTraceEnabled()) { log.trace("New socket connection {}", ch); ch.closeFuture().addListener(future -> log.trace("channel closed {}", ch)); } pipeline.addLast("decoder", new HttpRequestDecoder(maxInitialLineLength,maxHeaderSize,maxChunkSize)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength)); // compression is neat, but a little buggy // pipeline.addLast(ImmediateEventExecutor.INSTANCE, "compressor", new HttpContentCompressor()); pipeline.addLast("query", httpQueryHandler); } }
@Override protected void initChannel(SocketChannel ch) throws Exception { ch.closeFuture().addListener(onCloseResetListener); ChannelPipeline pipeline = ch.pipeline(); SslHandler sslHandler = getSslHandler(discoverable, ch.alloc()); if (sslHandler != null) { pipeline.addLast("ssl", sslHandler); } pipeline.addLast("idle-state-handler", new IdleStateHandler(0, 0, cConf.getInt(Constants.Router.CONNECTION_TIMEOUT_SECS))); pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast("forwarder", new OutboundHandler(inboundChannel)); } });
@Override public ConsumerSpec readIdle(long idleTimeout, final Runnable onReadIdle) { final IdleReadListener irl = new IdleReadListener(idleTimeout, onReadIdle); channel.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { try { irl.channelInactive(null); } catch(NullPointerException ignored) {} } }); channel.pipeline().addFirst(irl); return this; }
@Override public void removeTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) { getChannel().closeFuture().removeListener(listener); }
@Override protected void initChannel(SocketChannel channel) throws Exception { channelCounter.inc(); logger.info("channel initialized: {}", channel); channel.pipeline().addLast(new LoggingHandler(LogLevel.TRACE)); channel.pipeline().addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder())); channel.pipeline().addLast(new ModbusTcpSlaveHandler(ModbusTcpSlave.this)); channel.closeFuture().addListener(future -> channelCounter.dec()); } };
@Override public void connectionSucceeded(final ServerConnection connection) { connection.getChannel().closeFuture().addListener( new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> future) throws Exception { for (final UserResultsListener listener : queryIdToResultsListenersMap.values()) { listener.submissionFailed(UserException.connectionError() .message("Connection %s closed unexpectedly. SabotNode down?", connection.getName()) .build(logger)); if (listener instanceof BufferingResultsListener) { // the appropriate listener will be failed by SubmissionListener#failed logger.warn("Buffering listener failed before results were transferred to the actual listener."); } } } }); parentHandler.connectionSucceeded(connection); }
@Override protected void initChannel(SocketChannel ch) throws Exception { connection = initRemoteConnection(ch); // each handler in the pipeline is created per connection ch.closeFuture().addListener(newCloseListener(ch, connection)); final ChannelPipeline pipe = ch.pipeline(); pipe.addLast(PROTOCOL_ENCODER, new RpcEncoder("c-" + rpcConfig.getName())); pipe.addLast(PROTOCOL_DECODER, newDecoder(connection.getAllocator())); pipe.addLast(HANDSHAKE_HANDLER, new ClientHandshakeHandler()); if (timeoutInMillis != -1) { pipe.addLast(IDLE_STATE_HANDLER, new IdlePingHandler(timeoutInMillis)); } pipe.addLast(MESSAGE_HANDLER, new InboundHandler(connection)); pipe.addLast(EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); } });
@Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); if(null != sslOpts) { SSLEngine ssl = new SSLEngineSupplier(sslOpts, true).get(); log.debug("SSL enabled using keystore {}", (null != sslOpts.keystoreFile() ? sslOpts.keystoreFile() : "<DEFAULT>")); ch.pipeline().addLast(new SslHandler(ssl)); } if(options instanceof NettyClientSocketOptions && null != ((NettyClientSocketOptions)options) .pipelineConfigurer()) { ((NettyClientSocketOptions)options).pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { connections.remove(ch); } }); } });
ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception {
ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception {
private NettyHandshakeServer createHandshakeServer( SocketChannel channel ) { HandshakeServer handshakeServer = new HandshakeServer( applicationProtocolRepository, modifierProtocolRepository, new SimpleNettyChannel( channel, log ) ); handshakeServer.protocolStackFuture().whenComplete( ( protocolStack, failure ) -> onHandshakeComplete( protocolStack, channel, failure ) ); channel.closeFuture().addListener( f -> { try { channel.parent().pipeline().fireUserEventTriggered( new ServerHandshakeFinishedEvent.Closed( toSocketAddress( channel ) ) ); } catch ( RejectedExecutionException ignored ) { } } ); return new NettyHandshakeServer( handshakeServer ); }
ch.closeFuture().addListener(new GenericFutureListener() { @Override public void operationComplete(Future future) throws Exception {