private boolean futureIsAlreadyCancelled(Channel channel) { // FIXME should we only check isCancelled? if (future.isDone()) { Channels.silentlyCloseChannel(channel); return true; } return false; }
public void attachChannel(Channel channel, boolean reuseChannel) { // future could have been cancelled first if (isDone()) { Channels.silentlyCloseChannel(channel); } this.channel = channel; this.reuseChannel = reuseChannel; }
public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) { if (channel != null && channel.isActive()) { channelManager.closeChannel(channel); } if (!future.isDone()) { future.setChannelState(ChannelState.CLOSED); LOGGER.debug("Aborting Future {}\n", future); LOGGER.debug(t.getMessage(), t); future.abort(t); } }
/** * Return true if the {@link Future} can be recovered. There is some scenario * where a connection can be closed by an unexpected IOException, and in some * situation we can recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ public boolean isReplayPossible() { return !isDone() && !(Channels.isChannelActive(channel) && !getUri().getScheme().equalsIgnoreCase("https")) && inAuth == 0 && inProxyAuth == 0; }
public void run(Timeout timeout) { if (done.getAndSet(true) || requestSender.isClosed()) return; // in any case, cancel possible readTimeout sibling timeoutsHolder.cancel(); if (nettyResponseFuture.isDone()) return; StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder().append("Request timeout to "); appendRemoteAddress(sb); String message = sb.append(" after ").append(requestTimeout).append(" ms").toString(); long age = unpreciseMillisTime() - nettyResponseFuture.getStart(); expire(message, age); } }
return; if (nettyResponseFuture.isDone()) { timeoutsHolder.cancel(); return;
public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture<?> future) { if (Channels.isActiveTokenSet(channel)) { if (future.isDone()) { channelManager.closeChannel(channel); } else if (future.incrementRetryAndCheck() && retry(future)) { future.pendingException = null; } else { abort(channel, future, future.pendingException != null ? future.pendingException : RemotelyClosedException.INSTANCE); } } }
public void acquirePartitionLockLazily() throws IOException { if (connectionSemaphore == null || partitionKeyLock != null) { return; } Object partitionKey = getPartitionKey(); connectionSemaphore.acquireChannelLock(partitionKey); Object prevKey = PARTITION_KEY_LOCK_FIELD.getAndSet(this, partitionKey); if (prevKey != null) { // self-check connectionSemaphore.releaseChannelLock(prevKey); releasePartitionKeyLock(); throw new IllegalStateException("Trying to acquire partition lock concurrently. Please report."); } if (isDone()) { // may be cancelled while we acquired a lock releasePartitionKeyLock(); } }
@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 (future.isDone()) {
private boolean isChannelCloseable(Channel channel) { Object attribute = Channels.getAttribute(channel); if (attribute instanceof NettyResponseFuture) { NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute; if (!future.isDone()) { LOGGER.error("Future not in appropriate state %s, not closing", future); return false; } } return true; }
public void attachChannel(Channel channel, boolean reuseChannel) { // future could have been cancelled first if (isDone()) { Channels.silentlyCloseChannel(channel); } this.channel = channel; this.reuseChannel = reuseChannel; }
public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) { if (channel != null) channelManager.closeChannel(channel); if (!future.isDone()) { LOGGER.debug("Aborting Future {}\n", future); LOGGER.debug(t.getMessage(), t); future.abort(t); } }
public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) { if (channel != null) channelManager.closeChannel(channel); if (!future.isDone()) { future.setState(NettyResponseFuture.STATE.CLOSED); LOGGER.debug("Aborting Future {}\n", future); LOGGER.debug(t.getMessage(), t); future.abort(t); } }
public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture<?> future) { if (future.isDone()) channelManager.closeChannel(channel); else if (!retry(future)) abort(channel, future, REMOTELY_CLOSED_EXCEPTION); }
public void run(Timeout timeout) throws Exception { if (done.getAndSet(true) || requestSender.isClosed()) return; // in any case, cancel possible readTimeout sibling timeoutsHolder.cancel(); if (nettyResponseFuture.isDone()) return; String message = "Request timed out to " + remoteAddress + " of " + requestTimeout + " ms"; long age = millisTime() - nettyResponseFuture.getStart(); expire(message, age); } }
/** * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an * unexpected IOException, and in some situation we can recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ public boolean canBeReplayed() { return !isDone() && canRetry() && !(Channels.isChannelValid(channel) && !getUri().getScheme().equalsIgnoreCase("https")) && !isInAuth(); }
public void run(Timeout timeout) throws Exception { if (done.getAndSet(true) || requestSender.isClosed()) return; // in any case, cancel possible readTimeout sibling timeoutsHolder.cancel(); if (nettyResponseFuture.isDone()) return; String message = "Request timed out to " + remoteAddress + " of " + requestTimeout + " ms"; long age = millisTime() - nettyResponseFuture.getStart(); expire(message, age); } }
/** * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an * unexpected IOException, and in some situation we can recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ public boolean canBeReplayed() { return !isDone() && canRetry() && !(Channels.isChannelValid(channel) && !getUri().getScheme().equalsIgnoreCase("https")) && !isInAuth(); }
public void run(Timeout timeout) throws Exception { if (done.getAndSet(true) || requestSender.isClosed()) return; // in any case, cancel possible readTimeout sibling timeoutsHolder.cancel(); if (nettyResponseFuture.isDone()) return; String message = "Request timed out to " + remoteAddress + " of " + requestTimeout + " ms"; long age = millisTime() - nettyResponseFuture.getStart(); expire(message, age); } }