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%2FActivator.java;h=6f082b7ab186576c78c23b7e5c1c63df81d56b14;hb=1a43f55c49d91816751cec1825c40d0a90f8bd8b;hp=83029c44e665ec77bc5796535353277fe481ea43;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java index 83029c44e6..6f082b7ab1 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java @@ -8,48 +8,95 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; -import org.opendaylight.controller.config.yang.store.api.YangStoreService; +import static com.google.common.base.Preconditions.checkState; + +import java.util.Dictionary; +import java.util.Hashtable; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; +import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Hashtable; +public class Activator implements BundleActivator { -import static com.google.common.base.Preconditions.checkState; - -public class Activator implements BundleActivator, YangStoreServiceTracker.YangStoreTrackerListener { - - private static final Logger logger = LoggerFactory.getLogger(Activator.class); + private static final Logger LOG = LoggerFactory.getLogger(Activator.class); private BundleContext context; - ServiceRegistration osgiRegistration; + private ServiceRegistration osgiRegistration; + private ConfigRegistryLookupThread configRegistryLookup = null; @Override - public void start(BundleContext context) throws Exception { + public void start(final BundleContext context) throws Exception { this.context = context; - YangStoreServiceTracker tracker = new YangStoreServiceTracker(context, this); - tracker.open(); - } - @Override - public void stop(BundleContext context) throws Exception { + ServiceTrackerCustomizer customizer = new ServiceTrackerCustomizer() { + @Override + public ConfigRegistryLookupThread addingService(ServiceReference reference) { + LOG.debug("Got addingService(SchemaContextProvider) event, starting ConfigRegistryLookupThread"); + checkState(configRegistryLookup == null, "More than one onYangStoreAdded received"); + + SchemaContextProvider schemaContextProvider = reference.getBundle().getBundleContext().getService(reference); + + YangStoreService yangStoreService = new YangStoreService(schemaContextProvider, context); + configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService); + configRegistryLookup.start(); + return configRegistryLookup; + } + + @Override + public void modifiedService(ServiceReference reference, ConfigRegistryLookupThread configRegistryLookup) { + LOG.debug("Got modifiedService(SchemaContextProvider) event"); + final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference.getProperty(BindingRuntimeContext.class.getName()); + LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext); + configRegistryLookup.yangStoreService.refresh(runtimeContext); + + } + + @Override + public void removedService(ServiceReference reference, ConfigRegistryLookupThread configRegistryLookup) { + configRegistryLookup.interrupt(); + if (osgiRegistration != null) { + osgiRegistration.unregister(); + } + osgiRegistration = null; + Activator.this.configRegistryLookup = null; + } + }; + + ServiceTracker listenerTracker = new ServiceTracker<>(context, SchemaContextProvider.class, customizer); + listenerTracker.open(); } @Override - public synchronized void onYangStoreAdded(YangStoreService yangStoreService) { - checkState(osgiRegistration == null, "More than one onYangStoreAdded received"); - NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService); - logger.debug("Registering into OSGi"); - osgiRegistration = context.registerService(new String[]{NetconfOperationServiceFactory.class.getName()}, factory, - new Hashtable()); + public void stop(BundleContext context) { + if (configRegistryLookup != null) { + configRegistryLookup.interrupt(); + } } - @Override - public synchronized void onYangStoreRemoved() { - osgiRegistration.unregister(); - osgiRegistration = null; + private class ConfigRegistryLookupThread extends Thread { + private final YangStoreService yangStoreService; + + private ConfigRegistryLookupThread(YangStoreService yangStoreService) { + super("config-registry-lookup"); + this.yangStoreService = yangStoreService; + } + + @Override + public void run() { + NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService); + LOG.debug("Registering into OSGi"); + Dictionary properties = new Hashtable<>(); + properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.CONFIG_NETCONF_CONNECTOR); + osgiRegistration = context.registerService(NetconfOperationServiceFactory.class, factory, properties); + } } }