Bump upstreams to SNAPSHOTs
[netconf.git] / netconf / netconf-impl / src / main / java / org / opendaylight / netconf / impl / osgi / AggregatedNetconfOperationServiceFactory.java
index 5c292b1f6e5b9f70a7cca773554166c845db1339..9166cc41f62cf2591029435f5c907234cd8b2ab8 100644 (file)
@@ -5,22 +5,20 @@
  * 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.impl.osgi;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
-import com.google.common.collect.Sets;
-import io.netty.util.internal.ConcurrentSet;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import org.opendaylight.controller.config.util.capability.Capability;
+import java.util.concurrent.ConcurrentHashMap;
+import org.opendaylight.netconf.api.capability.Capability;
 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
 import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
@@ -33,15 +31,15 @@ import org.slf4j.LoggerFactory;
 /**
  * NetconfOperationService aggregator. Makes a collection of operation services accessible as one.
  */
-public class AggregatedNetconfOperationServiceFactory
+public final class AggregatedNetconfOperationServiceFactory
         implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(AggregatedNetconfOperationServiceFactory.class);
 
-    private final Set<NetconfOperationServiceFactory> factories = new ConcurrentSet<>();
+    private final Set<NetconfOperationServiceFactory> factories = ConcurrentHashMap.newKeySet();
     private final Multimap<NetconfOperationServiceFactory, AutoCloseable> registrations =
             Multimaps.synchronizedMultimap(HashMultimap.create());
-    private final Set<CapabilityListener> listeners = new ConcurrentSet<>();
+    private final Set<CapabilityListener> listeners = ConcurrentHashMap.newKeySet();
 
     public AggregatedNetconfOperationServiceFactory() {
     }
@@ -51,7 +49,7 @@ public class AggregatedNetconfOperationServiceFactory
     }
 
     @Override
-    public synchronized void onAddNetconfOperationServiceFactory(NetconfOperationServiceFactory service) {
+    public synchronized void onAddNetconfOperationServiceFactory(final NetconfOperationServiceFactory service) {
         factories.add(service);
 
         for (final CapabilityListener listener : listeners) {
@@ -62,7 +60,7 @@ public class AggregatedNetconfOperationServiceFactory
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public synchronized void onRemoveNetconfOperationServiceFactory(NetconfOperationServiceFactory service) {
+    public synchronized void onRemoveNetconfOperationServiceFactory(final NetconfOperationServiceFactory service) {
         factories.remove(service);
 
         for (final AutoCloseable autoCloseable : registrations.get(service)) {
@@ -78,7 +76,7 @@ public class AggregatedNetconfOperationServiceFactory
 
     @Override
     public Set<Capability> getCapabilities() {
-        final HashSet<Capability> capabilities = Sets.newHashSet();
+        final Set<Capability> capabilities = new HashSet<>();
         for (final NetconfOperationServiceFactory factory : factories) {
             capabilities.addAll(factory.getCapabilities());
         }
@@ -87,7 +85,7 @@ public class AggregatedNetconfOperationServiceFactory
 
     @Override
     public synchronized AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
-        final Map<NetconfOperationServiceFactory, AutoCloseable> regs = Maps.newHashMap();
+        final Map<NetconfOperationServiceFactory, AutoCloseable> regs = new HashMap<>();
 
         for (final NetconfOperationServiceFactory factory : factories) {
             final AutoCloseable reg = factory.registerCapabilityListener(listener);
@@ -95,15 +93,12 @@ public class AggregatedNetconfOperationServiceFactory
         }
         listeners.add(listener);
 
-        return new AutoCloseable() {
-            @Override
-            public void close() throws Exception {
-                synchronized (AggregatedNetconfOperationServiceFactory.this) {
-                    listeners.remove(listener);
-                    CloseableUtil.closeAll(regs.values());
-                    for (final Map.Entry<NetconfOperationServiceFactory, AutoCloseable> reg : regs.entrySet()) {
-                        registrations.remove(reg.getKey(), reg.getValue());
-                    }
+        return () -> {
+            synchronized (AggregatedNetconfOperationServiceFactory.this) {
+                listeners.remove(listener);
+                CloseableUtil.closeAll(regs.values());
+                for (final Map.Entry<NetconfOperationServiceFactory, AutoCloseable> reg : regs.entrySet()) {
+                    registrations.remove(reg.getKey(), reg.getValue());
                 }
             }
         };
@@ -134,12 +129,12 @@ public class AggregatedNetconfOperationServiceFactory
             for (final NetconfOperationServiceFactory factory : factories) {
                 b.add(factory.createService(netconfSessionIdForReporting));
             }
-            this.services = b.build();
+            services = b.build();
         }
 
         @Override
         public Set<NetconfOperation> getNetconfOperations() {
-            final HashSet<NetconfOperation> operations = Sets.newHashSet();
+            final Set<NetconfOperation> operations = new HashSet<>();
             for (final NetconfOperationService service : services) {
                 operations.addAll(service.getNetconfOperations());
             }