X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FNetconfOperationServiceFactoryImpl.java;h=6ea628d0190e8a531166c823efa4eff8bf6e5173;hb=refs%2Fchanges%2F13%2F23413%2F26;hp=82c04a50e09c9124773d565fc58f2e82b17cd9ff;hpb=10d39810f724474b84d0e6d3f5676a5154593ca2;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java index 82c04a50e0..6ea628d019 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java @@ -8,64 +8,56 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; -import java.lang.management.ManagementFactory; -import javax.management.MBeanServer; -import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import com.google.common.collect.Sets; +import java.util.Set; +import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory; +import org.opendaylight.controller.config.util.capability.Capability; +import org.opendaylight.controller.config.util.capability.ModuleListener; +import org.opendaylight.controller.config.util.capability.YangModuleCapability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.opendaylight.yangtools.yang.model.api.Module; public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory { - public static final int ATTEMPT_TIMEOUT_MS = 1000; - private static final int SILENT_ATTEMPTS = 30; + private final ConfigSubsystemFacadeFactory configFacadeFactory; - private final YangStoreService yangStoreService; - private final ConfigRegistryJMXClient jmxClient; - - private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class); - - public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) { - this(yangStoreService, ManagementFactory.getPlatformMBeanServer()); + public NetconfOperationServiceFactoryImpl(ConfigSubsystemFacadeFactory configFacadeFactory) { + this.configFacadeFactory = configFacadeFactory; } - public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) { - this.yangStoreService = yangStoreService; + @Override + public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { + return new NetconfOperationServiceImpl(configFacadeFactory.createFacade(netconfSessionIdForReporting), netconfSessionIdForReporting); + } - ConfigRegistryJMXClient configRegistryJMXClient; - int i = 0; - // Config registry might not be present yet, but will be eventually - while(true) { + @Override + public Set getCapabilities() { + return configFacadeFactory.getCurrentCapabilities(); + } - try { - configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer); - break; - } catch (IllegalStateException e) { - ++i; - if (i > SILENT_ATTEMPTS) { - LOG.info("JMX client not created after {} attempts, still trying", i, e); - } else { - LOG.debug("JMX client could not be created, reattempting, try {}", i, e); - } - try { - Thread.sleep(ATTEMPT_TIMEOUT_MS); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - throw new IllegalStateException("Interrupted while reattempting connection", e1); - } + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return configFacadeFactory.getYangStoreService().registerModuleListener(new ModuleListener() { + @Override + public void onCapabilitiesChanged(Set added, Set removed) { + listener.onCapabilitiesChanged( + transformModulesToCapabilities(added), transformModulesToCapabilities(removed)); } - } + }); + } - jmxClient = configRegistryJMXClient; - if (i > SILENT_ATTEMPTS) { - LOG.info("Created JMX client after {} attempts", i); - } else { - LOG.debug("Created JMX client after {} attempts", i); + private static final Function MODULE_TO_CAPABILITY = new Function() { + @Override + public Capability apply(final Module module) { + return new YangModuleCapability(module, module.getSource()); } - } + }; - @Override - public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { - return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); + public static Set transformModulesToCapabilities(Set modules) { + return Sets.newHashSet(Collections2.transform(modules, MODULE_TO_CAPABILITY)); } + }