Bail early from handleSalInitializationSuccess() 58/107258/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Aug 2023 11:29:58 +0000 (13:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Aug 2023 12:41:19 +0000 (14:41 +0200)
This is just a minor clean up to make the method a tad more readable.

Change-Id: I204cdac7715de3e8cf119b652dcdd9140a58f9f0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 311729eabe6bebf5bd920e1b1acaae4916549b6a)

plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/NetconfDevice.java

index 074f23639d4e5d4010fd7dad3b3b009747efbe34..11b735b986c1dd0d578479f2eeb07e9ea73d8e24 100644 (file)
@@ -214,23 +214,24 @@ public class NetconfDevice implements RemoteDevice<NetconfDeviceCommunicator> {
     private synchronized void handleSalInitializationSuccess(final RemoteDeviceCommunicator listener,
             final NetconfDeviceSchema deviceSchema, final NetconfSessionPreferences remoteSessionCapabilities,
             final Rpcs deviceRpc) {
-        //NetconfDevice.SchemaSetup can complete after NetconfDeviceCommunicator was closed. In that case do nothing,
-        //since salFacade.onDeviceDisconnected was already called.
-        if (connected) {
-            final var mount = deviceSchema.mountContext();
-            messageTransformer = new NetconfMessageTransformer(mount, true,
-                resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
-
-            // salFacade.onDeviceConnected has to be called before the notification handler is initialized
-            salFacade.onDeviceConnected(deviceSchema, remoteSessionCapabilities,
-                new RemoteDeviceServices(deviceRpc, deviceActionFactory == null ? null
-                    : deviceActionFactory.createDeviceAction(messageTransformer, listener)));
-            notificationHandler.onRemoteSchemaUp(messageTransformer);
-
-            LOG.info("{}: Netconf connector initialized successfully", id);
-        } else {
+        // NetconfDevice.SchemaSetup can complete after NetconfDeviceCommunicator was closed. In that case do nothing,
+        // since salFacade.onDeviceDisconnected was already called.
+        if (!connected) {
             LOG.warn("{}: Device communicator was closed before schema setup finished.", id);
+            return;
         }
+
+        messageTransformer = new NetconfMessageTransformer(deviceSchema.mountContext(), true,
+            resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
+
+        // Order is important here: salFacade has to see the device come up and then the notificationHandler can deliver
+        // whatever notifications have been held back
+        salFacade.onDeviceConnected(deviceSchema, remoteSessionCapabilities,
+            new RemoteDeviceServices(deviceRpc, deviceActionFactory == null ? null
+                : deviceActionFactory.createDeviceAction(messageTransformer, listener)));
+        notificationHandler.onRemoteSchemaUp(messageTransformer);
+
+        LOG.info("{}: Netconf connector initialized successfully", id);
     }
 
     private void handleSalInitializationFailure(final RemoteDeviceCommunicator listener, final Throwable cause) {