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=12469f66b7be00d2649f231f8e1471073eaa66bd;hpb=87837c5398976e1f44418e9f161efea9d5fa4e7c;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 12469f66b7..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,69 +8,56 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; -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 javax.management.MBeanServer; -import java.lang.management.ManagementFactory; +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 YangStoreService yangStoreService; - private final ConfigRegistryJMXClient jmxClient; + private final ConfigSubsystemFacadeFactory configFacadeFactory; - private static final Logger logger = 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) { - logger.info("JMX client not created after {} attempts, still trying", i, e); - } else { - logger.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) { - logger.info("Created JMX client after {} attempts", i); - } else { - logger.debug("Created JMX client after {} attempts", i); - } + }); } - @Override - public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { - try { - return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); - } catch (YangStoreException e) { - throw new IllegalStateException(e); + private static final Function MODULE_TO_CAPABILITY = new Function() { + @Override + public Capability apply(final Module module) { + return new YangModuleCapability(module, module.getSource()); } + }; + + public static Set transformModulesToCapabilities(Set modules) { + return Sets.newHashSet(Collections2.transform(modules, MODULE_TO_CAPABILITY)); } + }