Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / AggregatedNetconfOperationServiceFactory.java
index c299ac7d1a4f5623e89dbfd8bade655b8044cc89..d4a15e0dbde241583f5d3a2676c0821c4b365b50 100644 (file)
@@ -17,17 +17,22 @@ import com.google.common.collect.Sets;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import org.opendaylight.controller.netconf.api.Capability;
+import org.opendaylight.controller.config.util.capability.Capability;
 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * 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 static final Logger LOG = LoggerFactory.getLogger(AggregatedNetconfOperationServiceFactory.class);
 
     private final Set<NetconfOperationServiceFactory> factories = new HashSet<>();
     private final Multimap<NetconfOperationServiceFactory, AutoCloseable> registrations = HashMultimap.create();
@@ -51,7 +56,7 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio
             try {
                 autoCloseable.close();
             } catch (Exception e) {
-                // FIXME Issue warning
+                LOG.warn("Unable to close listener registration", e);
             }
         }
 
@@ -96,6 +101,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;