Example usage for io.netty.util.concurrent Future awaitUninterruptibly

List of usage examples for io.netty.util.concurrent Future awaitUninterruptibly

Introduction

In this page you can find the example usage for io.netty.util.concurrent Future awaitUninterruptibly.

Prototype

Future<V> awaitUninterruptibly();

Source Link

Document

Waits for this future to be completed without interruption.

Usage

From source file:com.ancun.netty.common.NettyBootstrapFactory.java

License:Apache License

/**
 * netty//  w  w w  . j  av  a2  s  .  c  o  m
 *
 * @param shouldWait   ??
  */
public void shutdownGracefully(boolean shouldWait) {

    if (workerGroup != null) {
        Future<?> workerFuture = workerGroup.shutdownGracefully();
        if (shouldWait) {
            workerFuture.awaitUninterruptibly();
        }
    }

    if (null != bossGroup) {
        Future<?> bossFuture = bossGroup.shutdownGracefully();
        if (shouldWait) {
            bossFuture.awaitUninterruptibly();
        }
    }
}

From source file:com.navercorp.pinpoint.grpc.server.ServerFactory.java

License:Apache License

public void close() {
    final Future<?> workerShutdown = this.workerEventLoopGroup.shutdownGracefully();
    workerShutdown.awaitUninterruptibly();
    ExecutorUtils.shutdownExecutorService(name + "-Channel-Worker", workerExecutor);

    final Future<?> bossShutdown = this.bossEventLoopGroup.shutdownGracefully();
    bossShutdown.awaitUninterruptibly();
    ExecutorUtils.shutdownExecutorService(name + "-Channel-Boss", bossExecutor);
}

From source file:net.tomp2p.connection.TestReservation.java

License:Apache License

/**
 * Unclean shutdown of pending connections.
 * /*from   w  ww  .j ava2  s .c om*/
 * @throws InterruptedException .
 */
@Test
public void testReservationTCPNonCleanShutdown2() throws InterruptedException {
    EventLoopGroup ev = new NioEventLoopGroup();
    final int round = 100;
    final int inner = 100;
    final int conn = 5;
    final int tcpMax = 500;
    for (int i = 0; i < round; i++) {
        ChannelClientConfiguration c = PeerBuilder.createDefaultChannelClientConfiguration();
        c.pipelineFilter(new MyPipeLine());
        c.maxPermitsTCP(tcpMax);
        Reservation r = new Reservation(ev, c);
        List<FutureChannelCreator> fcc = new ArrayList<FutureChannelCreator>();
        for (int j = 0; j < inner; j++) {
            FutureChannelCreator fc = r.create(0, conn);
            fc.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
                @Override
                public void operationComplete(final FutureChannelCreator future) throws Exception {
                    if (future.isFailed()) {
                        return;
                    }
                    final ChannelCreator cc = future.channelCreator();
                    final int timeout = 2000;
                    for (int k = 0; k < conn; k++) {
                        ChannelFuture channelFuture = cc.createTCP(SOCKET_ADDRESS, timeout,
                                new HashMap<String, Pair<EventExecutorGroup, ChannelHandler>>() {
                                }, new FutureResponse(null));
                        if (channelFuture == null) {
                            return;
                        }
                        channelFuture.addListener(new GenericFutureListener<ChannelFuture>() {
                            @Override
                            public void operationComplete(final ChannelFuture future) throws Exception {
                                future.channel().close();
                            }
                        });
                    }
                }
            });
            fcc.add(fc);
        }
        r.shutdown().awaitListenersUninterruptibly();
    }
    Future<?> f = ev.shutdownGracefully().awaitUninterruptibly();
    f.awaitUninterruptibly();
}

From source file:org.apache.hadoop.hbase.regionserver.wal.AsyncFSWAL.java

License:Apache License

private void waitForSafePoint() {
    Future<Void> roll;
    boolean scheduleTask;
    synchronized (waitingConsumePayloads) {
        if (!writerBroken && this.writer != null) {
            Promise<Void> promise = eventLoop.newPromise();
            if (consumerScheduled) {
                scheduleTask = false;/*  w  w w  . j  av a2s  .  c om*/
            } else {
                scheduleTask = consumerScheduled = true;
            }
            waitingConsumePayloads.addLast(new Payload(promise));
            roll = promise;
        } else {
            roll = eventLoop.newSucceededFuture(null);
            scheduleTask = false;
        }
    }
    if (scheduleTask) {
        eventLoop.execute(consumer);
    }
    roll.awaitUninterruptibly();
}

From source file:org.redisson.CommandExecutorService.java

License:Apache License

public <V> V get(Future<V> future) {
    future.awaitUninterruptibly();
    if (future.isSuccess()) {
        return future.getNow();
    }/*  www.  ja  va 2  s . c o  m*/
    throw future.cause() instanceof RedisException ? (RedisException) future.cause()
            : new RedisException("Unexpected exception while processing command", future.cause());
}

From source file:org.redisson.core.RedissonMultiLock.java

License:Apache License

private void unlockInner() {
    List<Future<Void>> futures = new ArrayList<Future<Void>>(locks.size());
    for (RLock lock : locks) {
        futures.add(lock.unlockAsync());
    }//from  ww  w.  j ava  2  s. c  om

    for (Future<Void> unlockFuture : futures) {
        unlockFuture.awaitUninterruptibly();
    }
}

From source file:org.restexpress.ServerBootstrapFactory.java

License:Apache License

public void shutdownGracefully(boolean shouldWait) {
    Future<?> workerFuture = workerGroup.shutdownGracefully();
    Future<?> bossFuture = bossGroup.shutdownGracefully();

    if (shouldWait) {
        workerFuture.awaitUninterruptibly();
        bossFuture.awaitUninterruptibly();
    }// w  w  w. ja va  2  s  .  com
}

From source file:org.restnext.server.Server.java

License:Apache License

private void stop(final boolean await) {
    if (bossGroup != null && workerGroup != null) {
        Future<?> futureWorkerShutdown = workerGroup.shutdownGracefully();
        Future<?> futureBossShutdown = bossGroup.shutdownGracefully();
        if (await) {
            futureWorkerShutdown.awaitUninterruptibly();
            futureBossShutdown.awaitUninterruptibly();
        }// w w w  .j  ava2s .  c o  m
    }
}

From source file:org.vootoo.client.netty.connect.SimpleConnectionPool.java

License:Apache License

public Channel acquireConnect() throws NettyConnectLessException {
    Future<Channel> future = acquire();

    // see https://netty.io/4.0/api/io/netty/channel/ChannelFuture.html
    // use bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout);
    // so await without timeout
    future.awaitUninterruptibly();

    assert future.isDone();

    if (future.isCancelled()) {
        // Connection attempt cancelled by user
        throw new NettyConnectLessException("connection cancelled tcp=" + socketAddress);
    } else if (!future.isSuccess()) {
        throw new NettyConnectLessException(
                "connect tcp=" + socketAddress + " fail within " + connectTimeout + "ms time!", future.cause());
    } else {//from w  ww . j av  a2s  .c o  m
        // Connection established successfully
        Channel channel = future.getNow();

        if (logger.isDebugEnabled()) {
            logger.debug("acquire connect success channel={}", channel);
        }

        assert channel != null;

        if (channel == null) {
            throw new NettyConnectLessException("connect tcp=" + socketAddress + " fail within "
                    + connectTimeout + "ms time, future.getNow return null!");
        }

        return channel;
    }
}