Split out strategy decision error handling 81/101381/7
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 18:59:29 +0000 (20:59 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 28 Jul 2022 23:39:07 +0000 (23:39 +0000)
When the strategy determines that a connection attempt should not be
made it will throw an exception. Peel this case out of the rest of
connection handling and add a dedicated message.

Change-Id: I9dd897f487421ba096240ebc9e3d999a7a5d7489
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java

index d7722fe3bcad1f0a2c921ed97b41cb01e9e0d62a..178be8bfe1f3ef13ec748eb6c2c39aad2af929f7 100644 (file)
@@ -43,11 +43,18 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
 
     @SuppressWarnings("checkstyle:illegalCatch")
     synchronized void connect() {
+        final int timeout;
         try {
-            final int timeout = strategy.getConnectTimeout();
+            timeout = strategy.getConnectTimeout();
+        } catch (Exception e) {
+            LOG.info("Connection to {} aborted due to strategy decision", address, e);
+            setFailure(e);
+            return;
+        }
 
-            LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
+        LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
 
+        try {
             if (address.isUnresolved()) {
                 address = new InetSocketAddress(address.getHostName(), address.getPort());
             }