BUG-2635 Netconf monitoring for md-sal netconf northbound
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / AggregatedNetconfOperationServiceFactory.java
index c299ac7d1a4f5623e89dbfd8bade655b8044cc89..ae68ecc120b5fb502a0c362d023ff81b7f469509 100644 (file)
@@ -22,12 +22,13 @@ import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener;
 import org.opendaylight.controller.netconf.util.CloseableUtil;
 
 /**
  * NetconfOperationService aggregator. Makes a collection of operation services accessible as one.
  */
-public class AggregatedNetconfOperationServiceFactory implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener {
+public class AggregatedNetconfOperationServiceFactory implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener, AutoCloseable {
 
     private final Set<NetconfOperationServiceFactory> factories = new HashSet<>();
     private final Multimap<NetconfOperationServiceFactory, AutoCloseable> registrations = HashMultimap.create();
@@ -96,6 +97,16 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio
         return new AggregatedNetconfOperation(factories, netconfSessionIdForReporting);
     }
 
+    @Override
+    public synchronized void close() throws Exception {
+        factories.clear();
+        for (AutoCloseable reg : registrations.values()) {
+            reg.close();
+        }
+        registrations.clear();
+        listeners.clear();
+    }
+
     private static final class AggregatedNetconfOperation implements NetconfOperationService {
 
         private final Set<NetconfOperationService> services;