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 timeoutMillis) throws InterruptedException;

Source Link

Document

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

Usage

From source file:com.navercorp.pinpoint.grpc.client.ChannelFactory.java

License:Apache License

public void close() {
    final Future<?> future = eventLoopGroup.shutdownGracefully();
    try {/*from  w  w w  .  ja  va 2  s.c o  m*/
        logger.debug("shutdown {}-eventLoopGroup", name);
        future.await(1000 * 3);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    ExecutorUtils.shutdownExecutorService(name + "-eventLoopExecutor", eventLoopExecutor);
    ExecutorUtils.shutdownExecutorService(name + "-executorService", executorService);
}

From source file:dorkbox.network.connection.Shutdownable.java

License:Apache License

void shutdownEventLoops() {
    // we want to WAIT until after the event executors have completed shutting down.
    List<Future<?>> shutdownThreadList = new LinkedList<Future<?>>();

    List<EventLoopGroup> loopGroups;
    synchronized (eventLoopGroups) {
        loopGroups = new ArrayList<EventLoopGroup>(eventLoopGroups.size());
        loopGroups.addAll(eventLoopGroups);
    }/*  w  w  w.j a v  a  2  s . c o  m*/

    for (EventLoopGroup loopGroup : loopGroups) {
        Future<?> future = loopGroup.shutdownGracefully(maxShutdownWaitTimeInMilliSeconds / 10,
                maxShutdownWaitTimeInMilliSeconds, TimeUnit.MILLISECONDS);
        shutdownThreadList.add(future);
        Thread.yield();
    }

    // now wait for them to finish!
    // It can take a few seconds to shut down the executor. This will affect unit testing, where connections are quickly created/stopped
    for (Future<?> f : shutdownThreadList) {
        try {
            f.await(maxShutdownWaitTimeInMilliSeconds);
        } catch (InterruptedException ignored) {
        }
        Thread.yield();
    }
}

From source file:io.moquette.server.netty.NettyAcceptor.java

License:Open Source License

public void close() {
    if (m_workerGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }/*from   w w w  .j a  v a2 s.c o m*/
    if (m_bossGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }
    Future workerWaiter = m_workerGroup.shutdownGracefully();
    Future bossWaiter = m_bossGroup.shutdownGracefully();

    try {
        workerWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    try {
        bossWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    MessageMetrics metrics = m_metricsCollector.computeMetrics();
    LOG.info("Msg read: {}, msg wrote: {}", metrics.messagesRead(), metrics.messagesWrote());

    BytesMetrics bytesMetrics = m_bytesMetricsCollector.computeMetrics();
    LOG.info(String.format("Bytes read: %d, bytes wrote: %d", bytesMetrics.readBytes(),
            bytesMetrics.wroteBytes()));
}

From source file:io.moquette.server.netty.NettyAcceptor__.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void close() {
    if (m_workerGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }/*w ww  .  ja va 2 s .c o  m*/
    if (m_bossGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }

    Future workerWaiter = m_workerGroup.shutdownGracefully();
    Future bossWaiter = m_bossGroup.shutdownGracefully();

    try {
        workerWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    try {
        bossWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    MessageMetrics metrics = m_metricsCollector.computeMetrics();
    LOG.info("Msg read: {}, msg wrote: {}", metrics.messagesRead(), metrics.messagesWrote());

    BytesMetrics bytesMetrics = m_bytesMetricsCollector.computeMetrics();
    LOG.info(String.format("Bytes read: %d, bytes wrote: %d", bytesMetrics.readBytes(),
            bytesMetrics.wroteBytes()));
}

From source file:org.jmqtt.broker.acceptor.NettyAcceptor.java

License:Open Source License

@PreDestroy
public void close() {
    if (workerGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }/*  ww w  .j  a v  a 2  s. c om*/
    if (bossGroup == null) {
        throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
    }
    Future workerWaiter = workerGroup.shutdownGracefully();
    Future bossWaiter = bossGroup.shutdownGracefully();

    try {
        workerWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    try {
        bossWaiter.await(100);
    } catch (InterruptedException iex) {
        throw new IllegalStateException(iex);
    }

    MessageMetrics metrics = metricsCollector.computeMetrics();
    LOG.info("Msg read: {}, msg wrote: {}", metrics.messagesRead(), metrics.messagesWrote());

    BytesMetrics bytesMetrics = bytesMetricsCollector.computeMetrics();
    LOG.info(String.format("Bytes read: %d, bytes wrote: %d", bytesMetrics.readBytes(),
            bytesMetrics.wroteBytes()));

    LOG.info("jmqtt server closed");
}

From source file:org.waarp.common.crypto.ssl.WaarpSslUtility.java

License:Open Source License

/**
 * Wait for the handshake on the given channel (better to use addSslHandler when handler is added after channel is active)
 * //w w  w . j a va  2 s  .c  o m
 * @param channel
 * @return True if the Handshake is done correctly
 */
public static boolean waitForHandshake(Channel channel) {
    final ChannelHandler handler = channel.pipeline().first();
    if (handler instanceof SslHandler) {
        logger.debug("Start handshake SSL: " + channel);
        final SslHandler sslHandler = (SslHandler) handler;
        // Get the SslHandler and begin handshake ASAP.
        // Get notified when SSL handshake is done.
        Future<Channel> handshakeFuture = sslHandler.handshakeFuture();
        try {
            handshakeFuture.await(sslHandler.getHandshakeTimeoutMillis() + 100);
        } catch (InterruptedException e1) {
        }
        logger.debug("Handshake: " + handshakeFuture.isSuccess() + ": " + channel, handshakeFuture.cause());
        if (!handshakeFuture.isSuccess()) {
            channel.close();
            return false;
        }
        return true;
    } else {
        logger.error("SSL Not found but connected: " + handler.getClass().getName());
        return true;
    }
}