Merge "Log the address and port when binding fails"
authorAnil Vishnoi <vishnoianil@gmail.com>
Thu, 10 Jan 2019 17:17:51 +0000 (17:17 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 10 Jan 2019 17:17:51 +0000 (17:17 +0000)
1  2 
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpHandler.java

index 46dfd14d40cbec1b26c3407f8ac3ac04af3d25d4,4eb67cfd51e6b3b570d613221ce2f9293144e1ec..288c58c92968612ad31f8117c7b2204d0351aa6a
@@@ -51,7 -51,6 +51,7 @@@ public class TcpHandler implements Serv
      private int port;
      private String address;
      private final InetAddress startupAddress;
 +    private final Runnable readyRunnable;
      private EventLoopGroup workerGroup;
      private EventLoopGroup bossGroup;
      private final SettableFuture<Boolean> isOnlineFuture;
@@@ -66,8 -65,8 +66,8 @@@
       *
       * @param port listening port of TCPHandler server
       */
 -    public TcpHandler(final int port) {
 -        this(null, port);
 +    public TcpHandler(final int port, Runnable readyRunnable) {
 +        this(null, port, readyRunnable);
      }
  
      /**
       * @param address listening address of TCPHandler server
       * @param port listening port of TCPHandler server
       */
 -    public TcpHandler(final InetAddress address, final int port) {
 +    public TcpHandler(final InetAddress address, final int port, Runnable readyRunnable) {
          this.port = port;
          this.startupAddress = address;
          isOnlineFuture = SettableFuture.create();
 +        this.readyRunnable = readyRunnable;
      }
  
      /**
       * Starts server on selected port.
       */
      @Override
+     @SuppressWarnings("checkstyle:IllegalCatch")
      public void run() {
          /*
           * We generally do not perform IO-unrelated tasks, so we want to have
          } catch (InterruptedException e) {
              LOG.error("Interrupted while binding port {}", port, e);
              return;
+         } catch (Throwable throwable) {
+             // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+             LOG.error("Error while binding address {} and port {}", startupAddress, port, throwable);
+             throw throwable;
          }
  
          try {
              LOG.debug("address from tcphandler: {}", address);
              isOnlineFuture.set(true);
              LOG.info("Switch listener started and ready to accept incoming tcp/tls connections on port: {}", port);
 +
 +            readyRunnable.run();
 +
 +            // This waits until this channel is closed, and rethrows the cause of the failure if this future failed.
              f.channel().closeFuture().sync();
          } catch (InterruptedException e) {
              LOG.error("Interrupted while waiting for port {} shutdown", port, e);
index 32f164be9c8b5342c43eacdef9f5f58e74ab50ce,ac61d67a7f5dce03966436609c689cbb46fdca44..0fef5d45399fdf67b956d48d296b9b1423836617
@@@ -32,12 -32,11 +32,12 @@@ import org.slf4j.LoggerFactory
   */
  public final class UdpHandler implements ServerFacade {
  
 -    private static final Logger LOG = LoggerFactory
 -            .getLogger(UdpHandler.class);
 +    private static final Logger LOG = LoggerFactory.getLogger(UdpHandler.class);
 +
      private int port;
      private EventLoopGroup group;
      private final InetAddress startupAddress;
 +    private final Runnable readyRunnable;
      private final SettableFuture<Boolean> isOnlineFuture;
      private UdpChannelInitializer channelInitializer;
      private ThreadConfiguration threadConfig;
@@@ -48,8 -47,8 +48,8 @@@
       *
       * @param port listening port of UdpHandler server
       */
 -    public UdpHandler(final int port) {
 -        this(null, port);
 +    public UdpHandler(final int port, Runnable readyRunnable) {
 +        this(null, port, readyRunnable);
      }
  
      /**
       * @param address listening address of UdpHandler server
       * @param port listening port of UdpHandler server
       */
 -    public UdpHandler(final InetAddress address, final int port) {
 +    public UdpHandler(final InetAddress address, final int port, Runnable readyRunnable) {
          this.port = port;
          this.startupAddress = address;
          isOnlineFuture = SettableFuture.create();
 +        this.readyRunnable = readyRunnable;
      }
  
      @Override
+     @SuppressWarnings("checkstyle:IllegalCatch")
      public void run() {
          final ChannelFuture f;
          try {
          } catch (InterruptedException e) {
              LOG.error("Interrupted while binding port {}", port, e);
              return;
+         } catch (Throwable throwable) {
+             // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+             LOG.error("Error while binding address {} and port {}", startupAddress, port, throwable);
+             throw throwable;
          }
  
          try {
@@@ -92,8 -95,6 +97,8 @@@
              LOG.debug("Address from udpHandler: {}", address);
              isOnlineFuture.set(true);
              LOG.info("Switch listener started and ready to accept incoming udp connections on port: {}", port);
 +            readyRunnable.run();
 +            // This waits until this channel is closed, and rethrows the cause of the failure if this future failed.
              f.channel().closeFuture().sync();
          } catch (InterruptedException e) {
              LOG.error("Interrupted while waiting for port {} shutdown", port, e);