@Override protected void onSuccess(List<InetSocketAddress> addresses) { NettyConnectListener<T> connectListener = new NettyConnectListener<>(future, NettyRequestSender.this, channelManager, connectionSemaphore); NettyChannelConnector connector = new NettyChannelConnector(request.getLocalAddress(), addresses, asyncHandler, clientState); if (!future.isDone()) { // Do not throw an exception when we need an extra connection for a redirect // FIXME why? This violate the max connection per host handling, right? channelManager.getBootstrap(request.getUri(), request.getNameResolver(), proxy) .addListener((Future<Bootstrap> whenBootstrap) -> { if (whenBootstrap.isSuccess()) { connector.connect(whenBootstrap.get(), connectListener); } else { abort(null, future, whenBootstrap.cause()); } }); } }
if (futureIsAlreadyCancelled(channel)) { return; sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost(), proxyServer != null); } catch (Exception sslError) { onFailure(channel, sslError); return; } catch (Exception e) { LOGGER.error("onTlsHandshakeAttempt crashed", e); onFailure(channel, e); return; writeRequest(channel);
public final void operationComplete(ChannelFuture f) throws Exception { if (f.isSuccess()) onFutureSuccess(f.channel()); else onFutureFailure(f.channel(), f.cause()); } }
private void onFutureFailure(Channel channel, Throwable cause) { abortChannelPreemption(); boolean canRetry = future.canRetry(); LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry); if (canRetry && cause != null && (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) { if (requestSender.retry(future)) return; } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); boolean printCause = cause != null && cause.getMessage() != null; String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri()); ConnectException e = new ConnectException(printedCause); if (cause != null) { e.initCause(cause); } future.abort(e); }
private void onFutureSuccess(final Channel channel) throws ConnectException { SslHandler sslHandler = channel.pipeline().get(SslHandler.class); if (sslHandler != null) { sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.cause()); } } }); } else { writeRequest(channel); } }
private void writeRequest(Channel channel) { if (futureIsAlreadyCancelled(channel)) { return; } if (LOGGER.isDebugEnabled()) { HttpRequest httpRequest = future.getNettyRequest().getHttpRequest(); LOGGER.debug("Using new Channel '{}' for '{}' to '{}'", channel, httpRequest.method(), httpRequest.uri()); } Channels.setAttribute(channel, future); channelManager.registerOpenChannel(channel); future.attachChannel(channel, false); requestSender.writeRequest(future, channel); }
public final void operationComplete(ChannelFuture f) throws Exception { if (f.isSuccess()) onFutureSuccess(f.channel()); else onFutureFailure(f.channel(), f.cause()); } }
private void onFutureFailure(Channel channel, Throwable cause) { abortChannelPreemption(); boolean canRetry = future.canRetry(); LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry); if (canRetry// && cause != null// && (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) { if (requestSender.retry(future)) { return; } } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); boolean printCause = cause != null && cause.getMessage() != null; String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri()); ConnectException e = new ConnectException(printedCause); if (cause != null) e.initCause(cause); future.abort(e); }
private void onFutureSuccess(final Channel channel) throws ConnectException { SslHandler sslHandler = channel.getPipeline().get(SslHandler.class); if (sslHandler != null) { sslHandler.handshake().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.getCause()); } } }); } else { writeRequest(channel); } }
public final void operationComplete(ChannelFuture f) throws Exception { Channel channel = f.getChannel(); if (f.isSuccess()) onFutureSuccess(channel); else onFutureFailure(channel, f.getCause()); } }
private void onFutureFailure(Channel channel, Throwable cause) { abortChannelPreemption(); boolean canRetry = future.canRetry(); LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry); if (canRetry// && cause != null// && (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) { if (requestSender.retry(future)) { return; } } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); boolean printCause = cause != null && cause.getMessage() != null; String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri()); ConnectException e = new ConnectException(printedCause); if (cause != null) e.initCause(cause); future.abort(e); }
channelFuture.addListener(new NettyConnectListener<T>(future, this, channelManager, channelPreempted, partitionKey));
private void onFutureSuccess(final Channel channel) throws Exception { Request request = future.getRequest(); Uri uri = request.getUri(); // in case of proxy tunneling, we'll add the SslHandler later, after the CONNECT request if (future.getProxyServer() == null && uri.isSecured()) { SslHandler sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost()); sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.cause()); } } }); } else { writeRequest(channel); } }
public final void operationComplete(ChannelFuture f) throws Exception { Channel channel = f.getChannel(); if (f.isSuccess()) onFutureSuccess(channel); else onFutureFailure(channel, f.getCause()); } }
private void onFutureFailure(Channel channel, Throwable cause) { abortChannelPreemption(); boolean canRetry = future.canRetry(); LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry); if (canRetry && cause != null && (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) { if (requestSender.retry(future)) return; } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); boolean printCause = cause != null && cause.getMessage() != null; String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri()); ConnectException e = new ConnectException(printedCause); if (cause != null) { e.initCause(cause); } future.abort(e); }
.connect(bootstrap, new NettyConnectListener<T>(future, this, channelManager, channelPreempted, partitionKey));
private void onFutureSuccess(final Channel channel) throws Exception { Request request = future.getRequest(); Uri uri = request.getUri(); // in case of proxy tunneling, we'll add the SslHandler later, after the CONNECT request if (future.getProxyServer() == null && uri.isSecured()) { SslHandler sslHandler = channelManager.addSslHandler(channel.getPipeline(), uri, request.getVirtualHost()); sslHandler.handshake().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.getCause()); } } }); } else { writeRequest(channel); } }
private void writeRequest(Channel channel) { LOGGER.debug("Using non-cached Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri()); Channels.setAttribute(channel, future); if (future.isDone()) { abortChannelPreemption(); return; } future.attachChannel(channel, false); channelManager.registerOpenChannel(channel, partitionKey); requestSender.writeRequest(future, channel); }
.connect(bootstrap, new NettyConnectListener<T>(future, this, channelManager, channelPreempted, partitionKey));
private void writeRequest(Channel channel) { LOGGER.debug("Using non-cached Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri()); Channels.setAttribute(channel, future); if (future.isDone()) { abortChannelPreemption(); return; } if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onConnectionOpen(); channelManager.registerOpenChannel(channel, partitionKey); future.attachChannel(channel, false); requestSender.writeRequest(future, channel); }