Cache netconf operations 19/79219/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Jan 2019 03:05:08 +0000 (04:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Jan 2019 03:05:08 +0000 (04:05 +0100)
NetconfMonitoringOperationService is creating operations on demand,
where these are immutable and can be freely reused.

Instantiate them exactly once and keep them around for reuse.

Change-Id: If0ed07af0863dba0e715c4ce0447d22289a3475f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-monitoring/src/main/java/org/opendaylight/netconf/monitoring/Get.java
netconf/netconf-monitoring/src/main/java/org/opendaylight/netconf/monitoring/osgi/NetconfMonitoringOperationService.java

index 4eaf60496c69352465de68969c35dfa76f7e3cd1..6b80a135489acef199c1970405c0f6e03debbf27 100644 (file)
@@ -32,8 +32,7 @@ public class Get extends AbstractNetconfOperation {
         this.netconfMonitor = netconfMonitor;
     }
 
-    private Element getPlaceholder(final Document innerResult)
-            throws DocumentedException {
+    private static Element getPlaceholder(final Document innerResult) throws DocumentedException {
         final XmlElement rootElement = XmlElement.fromDomElementWithExpected(
                 innerResult.getDocumentElement(), XmlNetconfConstants.RPC_REPLY_KEY,
                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
index 7bdeac6af5c1c80ecb12a6e64cfde163f3b7a6eb..e1d8b1e82ce149aadd5d876870298cd7872ddc0f 100644 (file)
@@ -5,10 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.monitoring.osgi;
 
-import com.google.common.collect.Sets;
+import com.google.common.collect.ImmutableSet;
 import java.util.Set;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.mapping.api.NetconfOperation;
@@ -18,15 +17,15 @@ import org.opendaylight.netconf.monitoring.GetSchema;
 
 public class NetconfMonitoringOperationService implements NetconfOperationService {
 
-    private final NetconfMonitoringService monitor;
+    private final ImmutableSet<NetconfOperation> netconfOperations;
 
     public NetconfMonitoringOperationService(final NetconfMonitoringService monitor) {
-        this.monitor = monitor;
+        netconfOperations = ImmutableSet.of(new Get(monitor), new GetSchema(monitor));
     }
 
     @Override
     public Set<NetconfOperation> getNetconfOperations() {
-        return Sets.newHashSet(new Get(monitor), new GetSchema(monitor));
+        return netconfOperations;
     }
 
     @Override