use of org.asynchttpclient.handler.AsyncHandlerExtensions in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method sendRequestWithOpenChannel.
private <T> ListenableFuture<T> sendRequestWithOpenChannel(Request request, ProxyServer proxy, NettyResponseFuture<T> future, AsyncHandler<T> asyncHandler, Channel channel) {
if (asyncHandler instanceof AsyncHandlerExtensions)
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled(channel);
TimeoutsHolder timeoutsHolder = scheduleRequestTimeout(future);
timeoutsHolder.initRemoteAddress((InetSocketAddress) channel.remoteAddress());
future.setChannelState(ChannelState.POOLED);
future.attachChannel(channel, false);
if (LOGGER.isDebugEnabled()) {
HttpRequest httpRequest = future.getNettyRequest().getHttpRequest();
LOGGER.debug("Using open Channel {} for {} '{}'", channel, httpRequest.method(), httpRequest.uri());
}
// channelInactive might be called between isChannelValid and writeRequest
// so if we don't store the Future now, channelInactive won't perform handleUnexpectedClosedChannel
Channels.setAttribute(channel, future);
if (Channels.isChannelValid(channel)) {
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;
}
use of org.asynchttpclient.handler.AsyncHandlerExtensions in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method replayRequest.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, Channel channel) {
Request newRequest = fc.getRequest();
future.setAsyncHandler(fc.getAsyncHandler());
future.setChannelState(ChannelState.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);
}
Aggregations