Make mappedRpcs an ImmutableMap 36/84936/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 23 Aug 2019 11:50:12 +0000 (13:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Oct 2019 06:20:49 +0000 (08:20 +0200)
This map is known to be immutable in all cases, make sure we
propagate that knowledge.

Change-Id: Iac97ab3227b88ae6fd5e6fadd896f357412947a2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 18ff92b521bd02297e0871150f8d79df964180b4)

netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseSchema.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java

index a1641e64c0eb34ae3fe68e21e1a6d2962c0a0621..12d71a7843e4144f72109d579a78c3ec3b9746f4 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import java.util.Arrays;
-import java.util.Map;
 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -35,7 +35,7 @@ public enum BaseSchema implements SchemaContextProvider {
             .$YangModuleInfoImpl.getInstance()
     );
 
-    private final Map<QName, RpcDefinition> mappedRpcs;
+    private final ImmutableMap<QName, RpcDefinition> mappedRpcs;
     private final SchemaContext schemaContext;
 
     BaseSchema(final YangModuleInfo... modules) {
@@ -45,7 +45,7 @@ public enum BaseSchema implements SchemaContextProvider {
         mappedRpcs = Maps.uniqueIndex(schemaContext.getOperations(), RpcDefinition::getQName);
     }
 
-    Map<QName, RpcDefinition> getMappedRpcs() {
+    ImmutableMap<QName, RpcDefinition> getMappedRpcs() {
         return mappedRpcs;
     }
 
index 52f5587e500cb07533058a5bb57aa2545ac06350..b3c0c803d52463026688af9c3c5c952d79d6853a 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
 import com.google.common.collect.Maps;
@@ -86,7 +87,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
     private final SchemaContext schemaContext;
     private final BaseSchema baseSchema;
     private final MessageCounter counter;
-    private final Map<QName, RpcDefinition> mappedRpcs;
+    private final ImmutableMap<QName, RpcDefinition> mappedRpcs;
     private final Multimap<QName, NotificationDefinition> mappedNotifications;
     private final boolean strictParsing;
     private final Set<ActionDefinition> actions;
@@ -184,7 +185,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         // and also check if the device exposed model for base netconf.
         // If no, use pre built base netconf operations model
         final boolean needToUseBaseCtx = mappedRpcs.get(rpcQName) == null && isBaseOrNotificationRpc(rpcQName);
-        final Map<QName, RpcDefinition> currentMappedRpcs;
+        final ImmutableMap<QName, RpcDefinition> currentMappedRpcs;
         if (needToUseBaseCtx) {
             currentMappedRpcs = baseSchema.getMappedRpcs();
         } else {
@@ -194,8 +195,8 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         final RpcDefinition mappedRpc = Preconditions.checkNotNull(currentMappedRpcs.get(rpcQName),
                 "Unknown rpc %s, available rpcs: %s", rpcQName, currentMappedRpcs.keySet());
         if (mappedRpc.getInput().getChildNodes().isEmpty()) {
-            return new NetconfMessage(NetconfMessageTransformUtil
-                    .prepareDomResultForRpcRequest(rpcQName, counter).getNode().getOwnerDocument());
+            return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpcQName, counter)
+                .getNode().getOwnerDocument());
         }
 
         Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpcQName);
@@ -281,15 +282,14 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                     new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME))
                     .withChild(anyXmlNode).build();
         } else {
-
-            Map<QName, RpcDefinition> currentMappedRpcs = mappedRpcs;
-
             // Determine whether a base netconf operation is being invoked
             // and also check if the device exposed model for base netconf.
             // If no, use pre built base netconf operations model
-            final boolean needToUseBaseCtx = mappedRpcs.get(rpcQName) == null && isBaseOrNotificationRpc(rpcQName);
-            if (needToUseBaseCtx) {
+            final ImmutableMap<QName, RpcDefinition> currentMappedRpcs;
+            if (mappedRpcs.get(rpcQName) == null && isBaseOrNotificationRpc(rpcQName)) {
                 currentMappedRpcs = baseSchema.getMappedRpcs();
+            } else {
+                currentMappedRpcs = mappedRpcs;
             }
 
             final RpcDefinition rpcDefinition = currentMappedRpcs.get(rpcQName);