Reduce ReconnectingStrategyListener nesting 76/101376/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 18:25:03 +0000 (20:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 18:25:03 +0000 (20:25 +0200)
We do not need to nest the two listeners into each other. This is the
first step to eliminating both of them.

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

index 5aba2df34e64c6152f41f522619f493b0da34306..f41153445236d47ffb126dfd93fdb8086a74e18a 100644 (file)
@@ -83,7 +83,6 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
         @Override
         public void operationComplete(final ChannelFuture cf) {
             synchronized (NetconfSessionPromise.this) {
-
                 LOG.debug("Promise {} connection resolved", NetconfSessionPromise.this);
 
                 // Triggered when a connection attempt is resolved.
@@ -118,28 +117,28 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
                 pending = rf;
             }
         }
+    }
+
+    private class ReconnectingStrategyListener implements FutureListener<Void> {
+        @Override
+        public void operationComplete(final Future<Void> sf) {
+            synchronized (NetconfSessionPromise.this) {
+                // Triggered when a connection attempt is to be made.
+                checkState(pending.equals(sf));
 
-        private class ReconnectingStrategyListener implements FutureListener<Void> {
-            @Override
-            public void operationComplete(final Future<Void> sf) {
-                synchronized (NetconfSessionPromise.this) {
-                    // Triggered when a connection attempt is to be made.
-                    checkState(pending.equals(sf));
-
-                    /*
-                     * The promise we gave out could have been cancelled,
-                     * which cascades to the reconnect attempt getting
-                     * cancelled, but there is a slight race window, where
-                     * the reconnect attempt is already enqueued, but the
-                     * listener has not yet been notified -- if cancellation
-                     * happens at that point, we need to catch it here.
-                     */
-                    if (!isCancelled()) {
-                        if (sf.isSuccess()) {
-                            connect();
-                        } else {
-                            setFailure(sf.cause());
-                        }
+                /*
+                 * The promise we gave out could have been cancelled,
+                 * which cascades to the reconnect attempt getting
+                 * cancelled, but there is a slight race window, where
+                 * the reconnect attempt is already enqueued, but the
+                 * listener has not yet been notified -- if cancellation
+                 * happens at that point, we need to catch it here.
+                 */
+                if (!isCancelled()) {
+                    if (sf.isSuccess()) {
+                        connect();
+                    } else {
+                        setFailure(sf.cause());
                     }
                 }
             }