io.netty.util.concurrent.Future.isDone()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中io.netty.util.concurrent.Future.isDone()方法的一些代码示例,展示了Future.isDone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.isDone()方法的具体详情如下:
包路径:io.netty.util.concurrent.Future
类名称:Future
方法名:isDone

Future.isDone介绍

暂无

代码示例

代码示例来源:origin: line/armeria

@Override
public boolean isDone() {
  return delegate.isDone();
}

代码示例来源:origin: netty/netty

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();
  }
}

代码示例来源:origin: redisson/redisson

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();
  }
}

代码示例来源:origin: lettuce-io/lettuce-core

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;
  }
}

代码示例来源:origin: netty/netty

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);
      }
    });
  }
}

代码示例来源:origin: netty/netty

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);
      }
    });
  }
}

代码示例来源:origin: wildfly/wildfly

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();
  }
}

代码示例来源:origin: redisson/redisson

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);
        }
      }
    });
  }
}

代码示例来源:origin: apache/incubator-pinot

/**
 * 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);
 }
}

代码示例来源:origin: redisson/redisson

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);
      }
    });
  }
}

代码示例来源:origin: redisson/redisson

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);
      }
    });
  }
}

代码示例来源:origin: wildfly/wildfly

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);
        }
      }
    });
  }
}

代码示例来源:origin: wildfly/wildfly

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);
      }
    });
  }
}

代码示例来源:origin: wildfly/wildfly

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);
      }
    });
  }
}

代码示例来源:origin: lettuce-io/lettuce-core

/**
 * 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;
}

代码示例来源:origin: redisson/redisson

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);

代码示例来源:origin: netty/netty

if (resolveFuture.isDone()) {
  final Throwable resolveFailureCause = resolveFuture.cause();

代码示例来源:origin: redisson/redisson

if (resolveFuture.isDone()) {
  final Throwable resolveFailureCause = resolveFuture.cause();

代码示例来源:origin: wildfly/wildfly

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);

代码示例来源:origin: line/armeria

@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;
}

相关文章