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

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

Introduction

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

Prototype

boolean await(long timeout, TimeUnit unit) throws InterruptedException;

Source Link

Document

Waits for this future to be completed within the specified time limit.

Usage

From source file:com.eucalyptus.ws.WebServices.java

License:Open Source License

private static EventLoopGroup clientEventLoopGroup() {
    if (clientEventLoopGroup != null) {
        return clientEventLoopGroup;
    } else/*from w  ww . j  a v  a2s  . c  o  m*/
        try (final LockResource resourceLock = LockResource.lock(clientResourceLock)) {
            if (clientEventLoopGroup != null) {
                return clientEventLoopGroup;
            } else {
                final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(
                        StackConfiguration.CLIENT_POOL_MAX_THREADS,
                        Threads.threadFactory("web-services-client-pool-%d"));
                OrderedShutdown.registerPostShutdownHook(() -> {
                    LOG.info("Client shutdown requested");
                    try {
                        final Future<?> terminationFuture = clientEventLoopGroup.shutdownGracefully(0, 5,
                                TimeUnit.SECONDS);
                        terminationFuture.await(10, TimeUnit.SECONDS);
                        if (terminationFuture.isDone()) {
                            LOG.info("Client shutdown complete");
                        } else {
                            LOG.warn("Client shutdown timed out");
                        }
                    } catch (final InterruptedException e) {
                        LOG.info("Client shutdown interrupted");
                    }
                });
                return clientEventLoopGroup = eventLoopGroup;
            }
        }
}

From source file:com.turo.pushy.apns.ApnsClientTest.java

License:Open Source License

@Test
@Parameters({ "true", "false" })
public void testRepeatedlySendNotificationAfterConnectionFailure(final boolean useTokenAuthentication)
        throws Exception {
    final ApnsClient client = useTokenAuthentication ? this.buildTokenAuthenticationClient()
            : this.buildTlsAuthenticationClient();

    try {//from   w w w .  jav  a  2  s. com
        final SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(DEVICE_TOKEN, TOPIC,
                PAYLOAD);

        for (int i = 0; i < 3; i++) {
            // We should see delays of roughly 0, 1, and 2 seconds; 4 seconds per notification is excessive, but
            // better to play it safe with a timed assertion.
            final Future<PushNotificationResponse<SimpleApnsPushNotification>> sendFuture = client
                    .sendNotification(pushNotification);

            assertTrue(sendFuture.await(4, TimeUnit.SECONDS));
            assertFalse(sendFuture.isSuccess());
        }
    } finally {
        client.close().await();
    }
}

From source file:org.aesh.terminal.ssh.tty.NettySshTtyTest.java

License:Open Source License

@After
public void after() throws Exception {
    Future<?> future = eventLoopGroup.shutdownGracefully();
    assertTrue(future.await(30, TimeUnit.SECONDS));
}

From source file:org.redisson.RedissonCountDownLatch.java

License:Apache License

@Override
public boolean await(long time, TimeUnit unit) throws InterruptedException {
    Future<Boolean> promise = subscribe();
    try {/*  w  w w  .ja  v  a 2 s  .  c om*/
        if (!promise.await(time, unit)) {
            return false;
        }

        time = unit.toMillis(time);
        while (getCountInner() > 0) {
            if (time <= 0) {
                return false;
            }
            long current = System.currentTimeMillis();
            // waiting for open state
            RedissonCountDownLatchEntry entry = ENTRIES.get(getEntryName());
            if (entry != null) {
                entry.getLatch().await(time, TimeUnit.MILLISECONDS);
            }

            long elapsed = System.currentTimeMillis() - current;
            time = time - elapsed;
        }

        return true;
    } finally {
        unsubscribe();
    }
}