Simplify base schema lookups 90/83990/7
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Aug 2019 13:20:06 +0000 (15:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 28 Aug 2019 12:30:39 +0000 (14:30 +0200)
We are checking for notification support multiple times, this
refactors the code to that only once.

Change-Id: Iaf453fc1de7f22e8a38e296f442c560daf66bf93
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java

index 9f7afe7ae0b801049e8950f5b264dc30e4caf93a..a56cd8c057c671728d1c35b81ccc18e65cb09586 100644 (file)
@@ -106,22 +106,6 @@ public class NetconfDevice
     // Message transformer is constructed once the schemas are available
     private MessageTransformer<NetconfMessage> messageTransformer;
 
-    /**
-     * Create rpc implementation capable of handling RPC for monitoring and notifications
-     * even before the schemas of remote device are downloaded.
-     */
-    static NetconfDeviceRpc getRpcForInitialization(final NetconfDeviceCommunicator listener,
-                                                    final boolean notificationSupport) {
-        final BaseSchema baseSchema = resolveBaseSchema(notificationSupport);
-
-        return new NetconfDeviceRpc(baseSchema.getSchemaContext(), listener,
-                new NetconfMessageTransformer(baseSchema.getMountPointContext(), false, baseSchema));
-    }
-
-    private static BaseSchema resolveBaseSchema(final boolean notificationSupport) {
-        return notificationSupport ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
-    }
-
     public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
                          final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
                          final ListeningExecutorService globalProcessingExecutor,
@@ -161,11 +145,11 @@ public class NetconfDevice
         setConnected(true);
         LOG.debug("{}: Session to remote device established with {}", id, remoteSessionCapabilities);
 
-        final NetconfDeviceRpc initRpc =
-                getRpcForInitialization(listener, remoteSessionCapabilities.isNotificationsSupported());
-        final DeviceSourcesResolver task =
-                new DeviceSourcesResolver(remoteSessionCapabilities, id, stateSchemasResolver, initRpc,
-                        resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()).getSchemaContext());
+        final BaseSchema baseSchema = resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported());
+        final NetconfDeviceRpc initRpc = new NetconfDeviceRpc(baseSchema.getSchemaContext(), listener,
+            new NetconfMessageTransformer(baseSchema.getMountPointContext(), false, baseSchema));
+        final DeviceSourcesResolver task = new DeviceSourcesResolver(remoteSessionCapabilities, id,
+            stateSchemasResolver, initRpc, baseSchema.getSchemaContext());
         final ListenableFuture<DeviceSources> sourceResolverFuture = processingExecutor.submit(task);
 
         if (shouldListenOnSchemaChange(remoteSessionCapabilities)) {
@@ -307,6 +291,10 @@ public class NetconfDevice
         notificationHandler.handleNotification(notification);
     }
 
+    private static BaseSchema resolveBaseSchema(final boolean notificationSupport) {
+        return notificationSupport ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
+    }
+
     /**
      * Just a transfer object containing schema related dependencies. Injected in constructor.
      */