use of org.asynchttpclient.netty.timeout.TimeoutsHolder 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.netty.timeout.TimeoutsHolder in project async-http-client by AsyncHttpClient.
the class NettyConnectListener method onSuccess.
public void onSuccess(Channel channel, InetSocketAddress remoteAddress) {
if (connectionSemaphore != null) {
// transfer lock from future to channel
Object partitionKeyLock = future.takePartitionKeyLock();
if (partitionKeyLock != null) {
channel.closeFuture().addListener(future -> connectionSemaphore.releaseChannelLock(partitionKeyLock));
}
}
Channels.setActiveToken(channel);
TimeoutsHolder timeoutsHolder = future.getTimeoutsHolder();
if (futureIsAlreadyCancelled(channel)) {
return;
}
Request request = future.getTargetRequest();
Uri uri = request.getUri();
timeoutsHolder.setResolvedRemoteAddress(remoteAddress);
ProxyServer proxyServer = future.getProxyServer();
// in case of proxy tunneling, we'll add the SslHandler later, after the CONNECT request
if ((proxyServer == null || proxyServer.getProxyType().isSocks()) && uri.isSecured()) {
SslHandler sslHandler;
try {
sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost(), proxyServer != null);
} catch (Exception sslError) {
onFailure(channel, sslError);
return;
}
final AsyncHandler<?> asyncHandler = future.getAsyncHandler();
try {
asyncHandler.onTlsHandshakeAttempt();
} catch (Exception e) {
LOGGER.error("onTlsHandshakeAttempt crashed", e);
onFailure(channel, e);
return;
}
sslHandler.handshakeFuture().addListener(new SimpleFutureListener<Channel>() {
@Override
protected void onSuccess(Channel value) {
try {
asyncHandler.onTlsHandshakeSuccess();
} catch (Exception e) {
LOGGER.error("onTlsHandshakeSuccess crashed", e);
NettyConnectListener.this.onFailure(channel, e);
return;
}
writeRequest(channel);
}
@Override
protected void onFailure(Throwable cause) {
try {
asyncHandler.onTlsHandshakeFailure(cause);
} catch (Exception e) {
LOGGER.error("onTlsHandshakeFailure crashed", e);
NettyConnectListener.this.onFailure(channel, e);
return;
}
NettyConnectListener.this.onFailure(channel, cause);
}
});
} else {
writeRequest(channel);
}
}
use of org.asynchttpclient.netty.timeout.TimeoutsHolder in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method scheduleRequestTimeout.
private TimeoutsHolder scheduleRequestTimeout(NettyResponseFuture<?> nettyResponseFuture) {
nettyResponseFuture.touch();
TimeoutsHolder timeoutsHolder = new TimeoutsHolder(nettyTimer, nettyResponseFuture, this, config);
nettyResponseFuture.setTimeoutsHolder(timeoutsHolder);
return timeoutsHolder;
}
use of org.asynchttpclient.netty.timeout.TimeoutsHolder in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method scheduleRequestTimeout.
private void scheduleRequestTimeout(NettyResponseFuture<?> nettyResponseFuture, InetSocketAddress originalRemoteAddress) {
nettyResponseFuture.touch();
TimeoutsHolder timeoutsHolder = new TimeoutsHolder(nettyTimer, nettyResponseFuture, this, config, originalRemoteAddress);
nettyResponseFuture.setTimeoutsHolder(timeoutsHolder);
}
use of org.asynchttpclient.netty.timeout.TimeoutsHolder in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method scheduleReadTimeout.
private void scheduleReadTimeout(NettyResponseFuture<?> nettyResponseFuture) {
TimeoutsHolder timeoutsHolder = nettyResponseFuture.getTimeoutsHolder();
if (timeoutsHolder != null) {
// on very fast requests, it's entirely possible that the response has already
// been completed
// by the time we try to schedule the read timeout
nettyResponseFuture.touch();
timeoutsHolder.startReadTimeout();
}
}
Aggregations