io.netty.util.concurrent.Future#await ( )源码实例Demo

下面列出了io.netty.util.concurrent.Future#await ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void close() {
    if (closed.compareAndSet(false, true)) {
        Future<?> closeCompleteFuture = doClose();

        try {
            if (!closeCompleteFuture.await(10, TimeUnit.SECONDS)) {
                throw new RuntimeException("Event loop didn't close after 10 seconds.");
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }

        Throwable exception = closeCompleteFuture.cause();
        if (exception != null) {
            throw new RuntimeException("Failed to close channel pool.", exception);
        }
    }
}
 
源代码2 项目: ambry   文件: Http2MultiplexedChannelPool.java
@Override
public void close() {
  if (closed.compareAndSet(false, true)) {
    Future<?> closeCompleteFuture = doClose();

    try {
      if (!closeCompleteFuture.await(10, TimeUnit.SECONDS)) {
        throw new RuntimeException("Event loop didn't close after 10 seconds.");
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException(e);
    }

    Throwable exception = closeCompleteFuture.cause();
    if (exception != null) {
      throw new RuntimeException("Failed to close channel pool.", exception);
    }
  }
}
 
源代码3 项目: cassandana   文件: NewNettyAcceptor.java
@SuppressWarnings("FutureReturnValueIgnored")
public void close() {
    LOG.debug("Closing Netty acceptor...");
    if (workerGroup == null || bossGroup == null) {
        LOG.error("Netty acceptor is not initialized");
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }
    Future<?> workerWaiter = workerGroup.shutdownGracefully();
    Future<?> bossWaiter = bossGroup.shutdownGracefully();

    /*
     * We shouldn't raise an IllegalStateException if we are interrupted. If we did so, the
     * broker is not shut down properly.
     */
    LOG.info("Waiting for worker and boss event loop groups to terminate...");
    try {
        workerWaiter.await(10, TimeUnit.SECONDS);
        bossWaiter.await(10, TimeUnit.SECONDS);
    } catch (InterruptedException iex) {
        LOG.warn("An InterruptedException was caught while waiting for event loops to terminate...");
    }

    if (!workerGroup.isTerminated()) {
        LOG.warn("Forcing shutdown of worker event loop...");
        workerGroup.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS);
    }

    if (!bossGroup.isTerminated()) {
        LOG.warn("Forcing shutdown of boss event loop...");
        bossGroup.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS);
    }
}
 
源代码4 项目: netty-4.1.22   文件: LocalChannelTest.java
@AfterClass
public static void afterClass() throws InterruptedException {
    Future<?> group1Future = group1.shutdownGracefully(0, 0, SECONDS);
    Future<?> group2Future = group2.shutdownGracefully(0, 0, SECONDS);
    Future<?> sharedGroupFuture = sharedGroup.shutdownGracefully(0, 0, SECONDS);
    group1Future.await();
    group2Future.await();
    sharedGroupFuture.await();
}
 
源代码5 项目: drift   文件: DriftNettyServerTransport.java
private static void await(Future<?> future)
{
    try {
        future.await();
    }
    catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
源代码6 项目: jlogstash-input-plugin   文件: Server.java
public void stop() throws InterruptedException {
    logger.debug("Requesting the server to stop.");
    Future<?> bossWait = bossGroup.shutdownGracefully(0, SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    Future<?> workWait = workGroup.shutdownGracefully(0, SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    bossWait.await();
    workWait.await();
    logger.debug("Server.stopped");
}
 
源代码7 项目: pinpoint   文件: DefaultChannelFactory.java
@Override
public void close() {
    final Future<?> future = eventLoopGroup.shutdownGracefully();
    try {
        logger.debug("shutdown {}-eventLoopGroup", factoryName);
        future.await(1000 * 3);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    ExecutorUtils.shutdownExecutorService(factoryName + "-eventLoopExecutor", eventLoopExecutor);
    ExecutorUtils.shutdownExecutorService(factoryName + "-executorService", executorService);
}