@Override public boolean isDone() { return delegate.isDone(); }
private void finishPeerRead0(LocalChannel peer) { Future<?> peerFinishReadFuture = peer.finishReadFuture; if (peerFinishReadFuture != null) { if (!peerFinishReadFuture.isDone()) { runFinishPeerReadTask(peer); return; } else { // Lazy unset to make sure we don't prematurely unset it while scheduling a new task. FINISH_READ_FUTURE_UPDATER.compareAndSet(peer, peerFinishReadFuture, null); } } // We should only set readInProgress to false if there is any data that was read as otherwise we may miss to // forward data later on. if (peer.readInProgress && !peer.inboundBuffer.isEmpty()) { peer.readInProgress = false; peer.readInbound(); } }
private void finishPeerRead0(LocalChannel peer) { Future<?> peerFinishReadFuture = peer.finishReadFuture; if (peerFinishReadFuture != null) { if (!peerFinishReadFuture.isDone()) { runFinishPeerReadTask(peer); return; } else { // Lazy unset to make sure we don't prematurely unset it while scheduling a new task. FINISH_READ_FUTURE_UPDATER.compareAndSet(peer, peerFinishReadFuture, null); } } // We should only set readInProgress to false if there is any data that was read as otherwise we may miss to // forward data later on. if (peer.readInProgress && !peer.inboundBuffer.isEmpty()) { peer.readInProgress = false; peer.readInbound(); } }
private static CompletableFuture<Void> toCompletableFuture(Future<?> future) { CompletableFuture<Void> promise = new CompletableFuture<>(); if (future.isDone() || future.isCancelled()) { if (future.isSuccess()) { promise.complete(null); } else { promise.completeExceptionally(future.cause()); } return promise; } future.addListener(f -> { if (f.isSuccess()) { promise.complete(null); } else { promise.completeExceptionally(f.cause()); } }); return promise; } }
private void doHealthCheckOnRelease(final Channel channel, final Promise<Void> promise) throws Exception { final Future<Boolean> f = healthCheck.isHealthy(channel); if (f.isDone()) { releaseAndOfferIfHealthy(channel, promise, f); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { releaseAndOfferIfHealthy(channel, promise, f); } }); } }
private void doHealthCheck(final Channel ch, final Promise<Channel> promise) { assert ch.eventLoop().inEventLoop(); Future<Boolean> f = healthCheck.isHealthy(ch); if (f.isDone()) { notifyHealthCheck(f, ch, promise); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { notifyHealthCheck(future, ch, promise); } }); } }
private void finishPeerRead0(LocalChannel peer) { Future<?> peerFinishReadFuture = peer.finishReadFuture; if (peerFinishReadFuture != null) { if (!peerFinishReadFuture.isDone()) { runFinishPeerReadTask(peer); return; } else { // Lazy unset to make sure we don't prematurely unset it while scheduling a new task. FINISH_READ_FUTURE_UPDATER.compareAndSet(peer, peerFinishReadFuture, null); } } // We should only set readInProgress to false if there is any data that was read as otherwise we may miss to // forward data later on. if (peer.readInProgress && !peer.inboundBuffer.isEmpty()) { peer.readInProgress = false; peer.readInbound(); } }
private void sendQuery(final DnsQuery query, final boolean flush, final ChannelPromise writePromise) { if (parent.channelFuture.isDone()) { writeQuery(query, flush, writePromise); } else { parent.channelFuture.addListener(new GenericFutureListener<Future<? super Channel>>() { @Override public void operationComplete(Future<? super Channel> future) { if (future.isSuccess()) { // If the query is done in a late fashion (as the channel was not ready yet) we always flush // to ensure we did not race with a previous flush() that was done when the Channel was not // ready yet. writeQuery(query, true, writePromise); } else { Throwable cause = future.cause(); promise.tryFailure(cause); writePromise.setFailure(cause); } } }); } }
/** * Blocking call to wait for shutdown completely. */ public void waitForShutdown(long millis) { LOGGER.info("Waiting for Shutdown"); if (_channel != null) { LOGGER.info("Closing the server channel"); long endTime = System.currentTimeMillis() + millis; ChannelFuture channelFuture = _channel.close(); Future<?> bossGroupFuture = _bossGroup.shutdownGracefully(); Future<?> workerGroupFuture = _workerGroup.shutdownGracefully(); long currentTime = System.currentTimeMillis(); if (endTime > currentTime) { channelFuture.awaitUninterruptibly(endTime - currentTime, TimeUnit.MILLISECONDS); } currentTime = System.currentTimeMillis(); if (endTime > currentTime) { bossGroupFuture.awaitUninterruptibly(endTime - currentTime, TimeUnit.MILLISECONDS); } currentTime = System.currentTimeMillis(); if (endTime > currentTime) { workerGroupFuture.awaitUninterruptibly(endTime - currentTime, TimeUnit.MILLISECONDS); } Preconditions.checkState(channelFuture.isDone(), "Unable to close the channel in %s ms", millis); Preconditions.checkState(bossGroupFuture.isDone(), "Unable to shutdown the boss group in %s ms", millis); Preconditions.checkState(workerGroupFuture.isDone(), "Unable to shutdown the worker group in %s ms", millis); } }
private void doHealthCheckOnRelease(final Channel channel, final Promise<Void> promise) throws Exception { final Future<Boolean> f = healthCheck.isHealthy(channel); if (f.isDone()) { releaseAndOfferIfHealthy(channel, promise, f); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { releaseAndOfferIfHealthy(channel, promise, f); } }); } }
private void doHealthCheck(final Channel ch, final Promise<Channel> promise) { assert ch.eventLoop().inEventLoop(); Future<Boolean> f = healthCheck.isHealthy(ch); if (f.isDone()) { notifyHealthCheck(f, ch, promise); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { notifyHealthCheck(future, ch, promise); } }); } }
private void sendQuery(final DnsQuery query, final ChannelPromise writePromise) { if (parent.channelFuture.isDone()) { writeQuery(query, writePromise); } else { parent.channelFuture.addListener(new GenericFutureListener<Future<? super Channel>>() { @Override public void operationComplete(Future<? super Channel> future) { if (future.isSuccess()) { writeQuery(query, writePromise); } else { Throwable cause = future.cause(); promise.tryFailure(cause); writePromise.setFailure(cause); } } }); } }
private void doHealthCheckOnRelease(final Channel channel, final Promise<Void> promise) throws Exception { final Future<Boolean> f = healthCheck.isHealthy(channel); if (f.isDone()) { releaseAndOfferIfHealthy(channel, promise, f); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { releaseAndOfferIfHealthy(channel, promise, f); } }); } }
private void doHealthCheck(final Channel ch, final Promise<Channel> promise) { assert ch.eventLoop().inEventLoop(); Future<Boolean> f = healthCheck.isHealthy(ch); if (f.isDone()) { notifyHealthCheck(f, ch, promise); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { notifyHealthCheck(future, ch, promise); } }); } }
/** * Create a promise that emits a {@code Boolean} value on completion of the {@code future} * * @param future the future. * @return Promise emitting a {@code Boolean} value. {@literal true} if the {@code future} completed successfully, otherwise * the cause wil be transported. */ static Promise<Boolean> toBooleanPromise(Future<?> future) { DefaultPromise<Boolean> result = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); if (future.isDone() || future.isCancelled()) { if (future.isSuccess()) { result.setSuccess(true); } else { result.setFailure(future.cause()); } return result; } future.addListener((GenericFutureListener<Future<Object>>) f -> { if (f.isSuccess()) { result.setSuccess(true); } else { result.setFailure(f.cause()); } }); return result; }
private void select(final ChannelHandlerContext ctx, final String hostname) throws Exception { Future<T> future = lookup(ctx, hostname); if (future.isDone()) { fireSniCompletionEvent(ctx, hostname, future); onLookupComplete(ctx, hostname, future);
if (resolveFuture.isDone()) { final Throwable resolveFailureCause = resolveFuture.cause();
if (resolveFuture.isDone()) { final Throwable resolveFailureCause = resolveFuture.cause();
private void select(final ChannelHandlerContext ctx, final String hostname) throws Exception { Future<T> future = lookup(ctx, hostname); if (future.isDone()) { fireSniCompletionEvent(ctx, hostname, future); onLookupComplete(ctx, hostname, future);
@Override public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception { if (!isValidPath(req)) { final IllegalArgumentException cause = new IllegalArgumentException("invalid path: " + req.path()); handleEarlyRequestException(ctx, req, cause); return HttpResponse.ofFailure(cause); } final Endpoint endpoint = ctx.endpoint().resolve(ctx) .withDefaultPort(ctx.sessionProtocol().defaultPort()); final EventLoop eventLoop = ctx.eventLoop(); final DecodedHttpResponse res = new DecodedHttpResponse(eventLoop); if (endpoint.hasIpAddr()) { // IP address has been resolved already. acquireConnectionAndExecute(ctx, endpoint, endpoint.ipAddr(), req, res); } else { // IP address has not been resolved yet. final Future<InetSocketAddress> resolveFuture = addressResolverGroup.getResolver(eventLoop) .resolve(InetSocketAddress.createUnresolved(endpoint.host(), endpoint.port())); if (resolveFuture.isDone()) { finishResolve(ctx, endpoint, resolveFuture, req, res); } else { resolveFuture.addListener( (FutureListener<InetSocketAddress>) future -> finishResolve(ctx, endpoint, future, req, res)); } } return res; }