X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fimpl%2Fosgi%2FAggregatedNetconfOperationServiceFactory.java;h=9166cc41f62cf2591029435f5c907234cd8b2ab8;hb=a3b728740edbefe3e39b10f8512c7a977cfa69fa;hp=938aec869f9cee8ebf4a355dcf8fa03008c48f66;hpb=4dac2dcf6e0f92a64e4303a0d6db788a6da41404;p=netconf.git diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java index 938aec869f..9166cc41f6 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java @@ -5,41 +5,41 @@ * 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; import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.opendaylight.netconf.util.CloseableUtil; -import org.opendaylight.netconf.api.monitoring.CapabilityListener; 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, AutoCloseable { +public final class AggregatedNetconfOperationServiceFactory + implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(AggregatedNetconfOperationServiceFactory.class); - private final Set factories = new ConcurrentSet<>(); - private final Multimap registrations = Multimaps.synchronizedMultimap(HashMultimap.create()); - private final Set listeners = new ConcurrentSet<>(); + private final Set factories = ConcurrentHashMap.newKeySet(); + private final Multimap registrations = + Multimaps.synchronizedMultimap(HashMultimap.create()); + private final Set listeners = ConcurrentHashMap.newKeySet(); public AggregatedNetconfOperationServiceFactory() { } @@ -49,7 +49,7 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio } @Override - public synchronized void onAddNetconfOperationServiceFactory(NetconfOperationServiceFactory service) { + public synchronized void onAddNetconfOperationServiceFactory(final NetconfOperationServiceFactory service) { factories.add(service); for (final CapabilityListener listener : listeners) { @@ -58,8 +58,9 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio } } + @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)) { @@ -75,7 +76,7 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio @Override public Set getCapabilities() { - final HashSet capabilities = Sets.newHashSet(); + final Set capabilities = new HashSet<>(); for (final NetconfOperationServiceFactory factory : factories) { capabilities.addAll(factory.getCapabilities()); } @@ -84,7 +85,7 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio @Override public synchronized AutoCloseable registerCapabilityListener(final CapabilityListener listener) { - final Map regs = Maps.newHashMap(); + final Map regs = new HashMap<>(); for (final NetconfOperationServiceFactory factory : factories) { final AutoCloseable reg = factory.registerCapabilityListener(listener); @@ -92,15 +93,12 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio } 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 reg : regs.entrySet()) { - registrations.remove(reg.getKey(), reg.getValue()); - } + return () -> { + synchronized (AggregatedNetconfOperationServiceFactory.this) { + listeners.remove(listener); + CloseableUtil.closeAll(regs.values()); + for (final Map.Entry reg : regs.entrySet()) { + registrations.remove(reg.getKey(), reg.getValue()); } } }; @@ -125,23 +123,25 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio private final Set services; - public AggregatedNetconfOperation(final Set factories, final String netconfSessionIdForReporting) { + AggregatedNetconfOperation(final Set factories, + final String netconfSessionIdForReporting) { final Builder b = ImmutableSet.builder(); for (final NetconfOperationServiceFactory factory : factories) { b.add(factory.createService(netconfSessionIdForReporting)); } - this.services = b.build(); + services = b.build(); } @Override public Set getNetconfOperations() { - final HashSet operations = Sets.newHashSet(); + final Set operations = new HashSet<>(); for (final NetconfOperationService service : services) { operations.addAll(service.getNetconfOperations()); } return operations; } + @SuppressWarnings("checkstyle:IllegalCatch") @Override public void close() { try {