@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()); } } });
private ChannelFuture connect(Request request, Uri uri, ProxyServer proxy, boolean useProxy, Bootstrap bootstrap, AsyncHandler<?> asyncHandler) throws UnknownHostException { InetSocketAddress remoteAddress = remoteAddress(request, uri, proxy, useProxy); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onDnsResolved(remoteAddress.getAddress()); if (request.getLocalAddress() != null) return bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); else return bootstrap.connect(remoteAddress); }
@Override public void operationComplete(ChannelFuture future) throws Exception { boolean retry = false; if (future.isSuccess()) { if (asyncHandlerExtensions != null) asyncHandlerExtensions.onConnectionSuccess(future.channel(), remoteAddress.getAddress()); } else { if (asyncHandlerExtensions != null) asyncHandlerExtensions.onConnectionFailure(remoteAddress.getAddress()); retry = pickNextRemoteAddress(); } if (retry) NettyChannelConnector.this.connect(bootstrap, listener); else listener.operationComplete(future); } });
@SuppressWarnings({ "rawtypes", "unchecked" }) public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, Channel channel) throws IOException { Request newRequest = fc.getRequest(); future.setAsyncHandler(fc.getAsyncHandler()); future.setState(NettyResponseFuture.STATE.NEW); future.touch(); LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRetry(); channelManager.drainChannelAndOffer(channel, future); sendNextRequest(newRequest, future); }
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); }
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled();
public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> handler, boolean keepAlive, Object partitionKey) { if (channel.isActive() && keepAlive && channel.isActive()) { LOGGER.debug("Adding key: {} for channel {}", partitionKey, channel); Channels.setDiscard(channel); if (handler instanceof AsyncHandlerExtensions) { AsyncHandlerExtensions.class.cast(handler).onConnectionOffer(channel); } channelPool.offer(channel, partitionKey); if (maxConnectionsPerHostEnabled) channelId2PartitionKey.putIfAbsent(channel, partitionKey); } else { // not offered closeChannel(channel); } }
private Channel pollAndVerifyCachedChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) { if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPool(); Uri uri = request.getUri(); String virtualHost = request.getVirtualHost(); final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getConnectionPoolPartitioning()); if (channel != null) { LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri); try { channelManager.verifyChannelPipeline(channel.pipeline(), uri, virtualHost); } catch (Exception ex) { LOGGER.debug(ex.getMessage(), ex); } } return channel; }
AsyncHandlerExtensions.class.cast(asyncHandler).onOpenConnection();
@SuppressWarnings({ "rawtypes", "unchecked" }) public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, Channel channel) { Request newRequest = fc.getRequest(); future.setAsyncHandler(fc.getAsyncHandler()); future.setState(NettyResponseFuture.STATE.NEW); future.touch(); LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRetry(); channelManager.drainChannelAndOffer(channel, future); sendNextRequest(newRequest, future); }
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); if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onConnectionOpen(); channelManager.registerOpenChannel(channel, partitionKey); requestSender.writeRequest(future, channel); }
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled();
public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> handler, boolean keepAlive, Object partitionKey) { if (channel.isConnected() && keepAlive && channel.isReadable()) { LOGGER.debug("Adding key: {} for channel {}", partitionKey, channel); Channels.setDiscard(channel); if (handler instanceof AsyncHandlerExtensions) { AsyncHandlerExtensions.class.cast(handler).onConnectionOffer(channel); } channelPool.offer(channel, partitionKey); if (maxConnectionsPerHostEnabled) channelId2PartitionKey.putIfAbsent(channel.getId(), partitionKey); } else { // not offered closeChannel(channel); } }
public Channel pollAndVerifyCachedChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) { if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPool(); Uri uri = request.getUri(); String virtualHost = request.getVirtualHost(); final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getConnectionPoolPartitioning()); if (channel != null) { LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri); try { // Always make sure the channel who got cached support the // proper protocol. It could // only occurs when a HttpMethod.CONNECT is used against a proxy // that requires upgrading from http to // https. channelManager.verifyChannelPipeline(channel.getPipeline(), uri, virtualHost); } catch (Exception ex) { LOGGER.debug(ex.getMessage(), ex); } } return channel; }
AsyncHandlerExtensions.class.cast(asyncHandler).onOpenConnection();
@SuppressWarnings({ "rawtypes", "unchecked" }) public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, Channel channel) throws IOException { final Request newRequest = fc.getRequest(); future.setAsyncHandler(fc.getAsyncHandler()); future.setState(NettyResponseFuture.STATE.NEW); future.touch(); LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRetry(); channelManager.drainChannelAndOffer(channel, future); sendNextRequest(newRequest, future); return; }
@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()); } } });
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionOpen();
private <T> ListenableFuture<T> sendRequestWithCachedChannel(Request request, ProxyServer proxy, NettyResponseFuture<T> future, AsyncHandler<T> asyncHandler, Channel channel) { if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled(channel); future.setState(NettyResponseFuture.STATE.POOLED); future.attachChannel(channel, false); LOGGER.debug("Using cached Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri()); if (Channels.isChannelValid(channel)) { Channels.setAttribute(channel, future); writeRequest(future, channel); } else { // bad luck, the channel was closed in-between // there's a very good chance onClose was already notified but the // future wasn't already registered handleUnexpectedClosedChannel(channel, future); } return future; }
@Override public void operationComplete(ChannelFuture future) throws Exception { boolean retry = false; if (future.isSuccess()) { if (asyncHandlerExtensions != null) asyncHandlerExtensions.onConnectionSuccess(future.getChannel(), remoteAddress.getAddress()); } else { if (asyncHandlerExtensions != null) asyncHandlerExtensions.onConnectionFailure(remoteAddress.getAddress()); retry = pickNextRemoteAddress(); } if (retry) NettyChannelConnector.this.connect(bootstrap, listener); else listener.operationComplete(future); } });