Java Code Examples for io.netty.channel.group.ChannelGroupFuture#isSuccess()

The following examples show how to use io.netty.channel.group.ChannelGroupFuture#isSuccess() . 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: ServerGroups.java    From serve with Apache License 2.0 6 votes vote down vote up
private void closeAllChannels(boolean graceful) {
    ChannelGroupFuture future = allChannels.close();

    // if this is a graceful shutdown, log any channel closing failures. if this isn't a
    // graceful shutdown, ignore them.
    if (graceful) {
        try {
            future.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        if (!future.isSuccess()) {
            for (ChannelFuture cf : future) {
                if (!cf.isSuccess()) {
                    logger.info("Unable to close channel: " + cf.channel(), cf.cause());
                }
            }
        }
    }
}
 
Example 2
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 6 votes vote down vote up
/**
 * Closes all channels opened by this proxy server.
 *
 * @param graceful when false, attempts to shutdown all channels immediately and ignores any channel-closing exceptions
 */
protected void closeAllChannels(boolean graceful) {
    LOG.info("Closing all channels " + (graceful ? "(graceful)" : "(non-graceful)"));

    ChannelGroupFuture future = allChannels.close();

    // if this is a graceful shutdown, log any channel closing failures. if this isn't a graceful shutdown, ignore them.
    if (graceful) {
        try {
            future.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();

            LOG.warn("Interrupted while waiting for channels to shut down gracefully.");
        }

        if (!future.isSuccess()) {
            for (ChannelFuture cf : future) {
                if (!cf.isSuccess()) {
                    LOG.info("Unable to close channel.  Cause of failure for {} is {}", cf.channel(), cf.cause());
                }
            }
        }
    }
}
 
Example 3
Source File: ServerGroups.java    From multi-model-server with Apache License 2.0 6 votes vote down vote up
private void closeAllChannels(boolean graceful) {
    ChannelGroupFuture future = allChannels.close();

    // if this is a graceful shutdown, log any channel closing failures. if this isn't a
    // graceful shutdown, ignore them.
    if (graceful) {
        try {
            future.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        if (!future.isSuccess()) {
            for (ChannelFuture cf : future) {
                if (!cf.isSuccess()) {
                    logger.info("Unable to close channel: " + cf.channel(), cf.cause());
                }
            }
        }
    }
}
 
Example 4
Source File: ProxyServer.java    From flashback with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Stop proxy server
 * */
public void stop() {
  ChannelGroupFuture future = _allChannels.close().awaitUninterruptibly();
  if (!future.isSuccess()) {
    final Iterator<ChannelFuture> iter = future.iterator();
    while (iter.hasNext()) {
      final ChannelFuture cf = iter.next();
      if (!cf.isSuccess()) {
        LOG.warn(String.format("Failed to close channel %s because %s", cf.channel(), cf.cause()));
      }
    }
  }
  _acceptorGroup.shutdownGracefully();
  _upstreamWorkerGroup.shutdownGracefully();
  _downstreamWorkerGroup.shutdownGracefully();
}
 
Example 5
Source File: NettyAcceptor.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void pause() {
   if (paused) {
      return;
   }

   if (channelClazz == null) {
      return;
   }

   // We *pause* the acceptor so no new connections are made
   if (serverChannelGroup != null) {
      ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly();
      if (!future.isSuccess()) {
         ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError();
         for (Channel channel : future.group()) {
            if (channel.isActive()) {
               ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress());
            }
         }
      }
   }
   paused = true;
}
 
Example 6
Source File: NettyAcceptor.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void asyncStop(Runnable callback) {
   if (channelClazz == null) {
      callback.run();
      return;
   }

   if (protocolHandler != null) {
      protocolHandler.close();
   }

   if (batchFlusherFuture != null) {
      batchFlusherFuture.cancel(false);

      flusher.cancel();

      flusher = null;

      batchFlusherFuture = null;
   }

   // serverChannelGroup has been unbound in pause()
   if (serverChannelGroup != null) {
      serverChannelGroup.close().awaitUninterruptibly();
   }

   if (channelGroup != null) {
      ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();

      if (!future.isSuccess()) {
         ActiveMQServerLogger.LOGGER.nettyChannelGroupError();
         for (Channel channel : future.group()) {
            if (channel.isActive()) {
               ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
            }
         }
      }
   }

   channelClazz = null;

   for (Connection connection : connections.values()) {
      listener.connectionDestroyed(connection.getID());
   }

   connections.clear();

   if (notificationService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName()));
      props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
      props.putIntProperty(new SimpleString("port"), port);
      Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
      try {
         notificationService.sendNotification(notification);
      } catch (Exception e) {
         ActiveMQServerLogger.LOGGER.failedToSendNotification(e);
      }
   }

   paused = false;

   // Shutdown the EventLoopGroup if no new task was added for 100ms or if
   // 3000ms elapsed.
   eventLoopGroup.shutdownGracefully(quietPeriod, shutdownTimeout, TimeUnit.MILLISECONDS).addListener(f -> callback.run());
   eventLoopGroup = null;
}