Java Code Examples for io.netty.util.concurrent.Future#awaitUninterruptibly()

The following examples show how to use io.netty.util.concurrent.Future#awaitUninterruptibly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteTransport.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
/**
 * Closes all channels and releases all resources.
 */
@Override
public void close() {
  LOG.info("Stopping listening at {} and closing", serverListeningChannel.localAddress());

  final ChannelFuture closeListeningChannelFuture = serverListeningChannel.close();
  final ChannelGroupFuture channelGroupCloseFuture = channelGroup.close();
  final Future serverListeningGroupCloseFuture = serverListeningGroup.shutdownGracefully();
  final Future serverWorkingGroupCloseFuture = serverWorkingGroup.shutdownGracefully();
  final Future clientGroupCloseFuture = clientGroup.shutdownGracefully();

  closeListeningChannelFuture.awaitUninterruptibly();
  channelGroupCloseFuture.awaitUninterruptibly();
  serverListeningGroupCloseFuture.awaitUninterruptibly();
  serverWorkingGroupCloseFuture.awaitUninterruptibly();
  clientGroupCloseFuture.awaitUninterruptibly();
}
 
Example 2
Source File: HttpClient.java    From esjc with MIT License 6 votes vote down vote up
@Override
public void close() {
    Future shutdownFuture = group.shutdownGracefully(0, 15, SECONDS);
    queueExecutor.shutdown();

    HttpOperation operation;
    while ((operation = queue.poll()) != null) {
        operation.response.completeExceptionally(new HttpClientException("Client closed"));
    }

    shutdownFuture.awaitUninterruptibly();

    try {
        queueExecutor.awaitTermination(5, SECONDS);
    } catch (InterruptedException e) {
        // ignore
    }
}
 
Example 3
Source File: ByteTransport.java    From nemo with Apache License 2.0 6 votes vote down vote up
/**
 * Closes all channels and releases all resources.
 */
@Override
public void close() {
  LOG.info("Stopping listening at {} and closing", serverListeningChannel.localAddress());

  final ChannelFuture closeListeningChannelFuture = serverListeningChannel.close();
  final ChannelGroupFuture channelGroupCloseFuture = channelGroup.close();
  final Future serverListeningGroupCloseFuture = serverListeningGroup.shutdownGracefully();
  final Future serverWorkingGroupCloseFuture = serverWorkingGroup.shutdownGracefully();
  final Future clientGroupCloseFuture = clientGroup.shutdownGracefully();

  closeListeningChannelFuture.awaitUninterruptibly();
  channelGroupCloseFuture.awaitUninterruptibly();
  serverListeningGroupCloseFuture.awaitUninterruptibly();
  serverWorkingGroupCloseFuture.awaitUninterruptibly();
  clientGroupCloseFuture.awaitUninterruptibly();
}
 
Example 4
Source File: NettyTcpTransport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
   if (closed.compareAndSet(false, true)) {
      connected.set(false);
      try {
         if (channel != null) {
            channel.close().syncUninterruptibly();
         }
      } finally {
         if (group != null) {
            Future<?> fut = group.shutdownGracefully(0, SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
            if (!fut.awaitUninterruptibly(2 * SHUTDOWN_TIMEOUT)) {
               LOG.trace("Channel group shutdown failed to complete in allotted time");
            }
         }
      }
   }
}
 
Example 5
Source File: NettyTcpTransport.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
    if (closed.compareAndSet(false, true)) {
        connected.set(false);
        try {
            if (channel != null) {
                channel.close().syncUninterruptibly();
            }
        } finally {
            if (group != null) {
                Future<?> fut = group.shutdownGracefully(0, SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
                if (!fut.awaitUninterruptibly(2 * SHUTDOWN_TIMEOUT)) {
                    LOG.trace("Channel group shutdown failed to complete in allotted time");
                }
            }
        }
    }
}
 
Example 6
Source File: TrackerService.java    From twill with Apache License 2.0 5 votes vote down vote up
@Override
protected void shutDown() throws Exception {
  channelGroup.close().awaitUninterruptibly();

  List<Future<?>> futures = new ArrayList<>();
  futures.add(bootstrap.config().group().shutdownGracefully(0, CLOSE_CHANNEL_TIMEOUT, TimeUnit.SECONDS));
  futures.add(bootstrap.config().childGroup().shutdownGracefully(0, CLOSE_CHANNEL_TIMEOUT, TimeUnit.SECONDS));

  for (Future<?> future : futures) {
    future.awaitUninterruptibly();
  }

  LOG.info("Tracker service stopped at {}", url);
}
 
Example 7
Source File: HttpClientTracingHandlerIntegrationTest.java    From xio with Apache License 2.0 5 votes vote down vote up
protected void get(XioClient client, String pathIncludingQuery) throws Exception {
  // System.out.println("get client: " + client + " path: " + pathIncludingQuery);
  HttpRequest payload = new DefaultFullHttpRequest(HTTP_1_1, GET, pathIncludingQuery);
  XioRequest<HttpRequest> request = buildRequest(client, payload);
  Future<Void> future = client.write(request);
  future.awaitUninterruptibly();
  try {
    local.get();
  } catch (Exception e) {
    // System.out.println("caught e: " + e);
  }
}
 
Example 8
Source File: ServerFactory.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: NettyMessagingTransport.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Closes all channels and releases all resources.
 */
@Override
public void close() {

  LOG.log(Level.FINE, "Closing netty transport socket address: {0}", this.localAddress);

  final ChannelGroupFuture clientChannelGroupFuture = this.clientChannelGroup.close();
  final ChannelGroupFuture serverChannelGroupFuture = this.serverChannelGroup.close();
  final ChannelFuture acceptorFuture = this.acceptor.close();

  final ArrayList<Future> eventLoopGroupFutures = new ArrayList<>(3);
  eventLoopGroupFutures.add(this.clientWorkerGroup.shutdownGracefully());
  eventLoopGroupFutures.add(this.serverBossGroup.shutdownGracefully());
  eventLoopGroupFutures.add(this.serverWorkerGroup.shutdownGracefully());

  clientChannelGroupFuture.awaitUninterruptibly();
  serverChannelGroupFuture.awaitUninterruptibly();

  try {
    acceptorFuture.sync();
  } catch (final Exception ex) {
    LOG.log(Level.SEVERE, "Error closing the acceptor channel for " + this.localAddress, ex);
  }

  for (final Future eventLoopGroupFuture : eventLoopGroupFutures) {
    eventLoopGroupFuture.awaitUninterruptibly();
  }

  LOG.log(Level.FINE, "Closing netty transport socket address: {0} done", this.localAddress);
}