From 594885b1c0800a4e9fb9588ac964b421a1906365 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Thu, 27 Nov 2014 15:22:54 -0500 Subject: [PATCH 1/1] Handle more specific BindException and IOException It is good pratice to handle specific exceptions rather than using the catch all generic Exception. This code change handles the java.net.BindException such that if an port is already in use we skip creating the simulated device on that port. IOException will display the failure message and exception and not cause additional attempts. Change-Id: I7cbf3aa7016b0589f8fdd3f6476006954068a9a0 Signed-off-by: Thanh Ha --- .../netconf/test/tool/NetconfDeviceSimulator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index adcdea6073..36e7dca761 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; +import java.net.BindException; import java.net.Inet4Address; import java.net.InetSocketAddress; import java.net.URI; @@ -197,14 +198,17 @@ public class NetconfDeviceSimulator implements Closeable { final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor); sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress)); sshWrappers.add(sshServer); - } catch (final Exception e) { - LOG.warn("Cannot start simulated device on {}, skipping", address, e); + } catch (final BindException e) { + LOG.warn("Cannot start simulated device on {}, port already in use. Skipping.", address); // Close local server and continue server.cancel(true); if(server.isDone()) { server.channel().close(); } continue; + } catch (final IOException e) { + LOG.warn("Cannot start simulated device on {} due to IOException.", address, e); + break; } finally { currentPort++; } -- 2.36.6