package org.opendaylight.mdsal.binding.dom.codec.osgi.impl;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import org.opendaylight.mdsal.binding.dom.codec.osgi.BindingRuntimeContextService;
import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
public final class Activator implements BundleActivator {
private final List<ServiceRegistration<?>> registrations = new ArrayList<>(2);
- private BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker = null;
+ private BundleTracker<?> moduleInfoResolvedBundleTracker = null;
private SimpleBindingRuntimeContextService service = null;
@Override
final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
moduleInfoBackedContext, service);
- final ModuleInfoBundleTracker moduleInfoTracker = new ModuleInfoBundleTracker(registry);
- moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING
- | Bundle.STOPPING | Bundle.ACTIVE, moduleInfoTracker);
+ moduleInfoResolvedBundleTracker = new ModuleInfoBundleTracker(context, registry);
moduleInfoResolvedBundleTracker.open();
- moduleInfoTracker.finishStart();
service.open();
registrations.add(context.registerService(BindingRuntimeContextService.class, service, null));
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry.
*/
-final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
+final class ModuleInfoBundleTracker extends BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> {
private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
// FIXME: this should be in a place shared with maven-sal-api-gen-plugin
private static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/";
private final OsgiModuleInfoRegistry moduleInfoRegistry;
- private volatile boolean starting = true;
+ private volatile boolean deferUpdates = true;
- ModuleInfoBundleTracker(final OsgiModuleInfoRegistry moduleInfoRegistry) {
+ ModuleInfoBundleTracker(final BundleContext context, final OsgiModuleInfoRegistry moduleInfoRegistry) {
+ super(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null);
this.moduleInfoRegistry = requireNonNull(moduleInfoRegistry);
}
- void finishStart() {
- starting = false;
+ @Override
+ public void open() {
+ super.open();
+ deferUpdates = false;
moduleInfoRegistry.updateService();
}
+ @Override
+ public void close() {
+ deferUpdates = true;
+ super.close();
+ }
+
@Override
@SuppressWarnings("checkstyle:illegalCatch")
public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(final Bundle bundle, final BundleEvent event) {
registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
}
- if (!starting) {
+ if (!deferUpdates) {
moduleInfoRegistry.updateService();
}