From 538fa4f7804e9aeab17282d27ed373481393bdf2 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 4 Aug 2023 13:29:58 +0200 Subject: [PATCH] Bail early from handleSalInitializationSuccess() This is just a minor clean up to make the method a tad more readable. Change-Id: I204cdac7715de3e8cf119b652dcdd9140a58f9f0 Signed-off-by: Robert Varga (cherry picked from commit 311729eabe6bebf5bd920e1b1acaae4916549b6a) --- .../netconf/client/mdsal/NetconfDevice.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/NetconfDevice.java b/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/NetconfDevice.java index 074f23639d..11b735b986 100644 --- a/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/NetconfDevice.java +++ b/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/NetconfDevice.java @@ -214,23 +214,24 @@ public class NetconfDevice implements RemoteDevice { 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) { -- 2.36.6