2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.osgi.impl;
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.dom.codec.osgi.BindingRuntimeContextService;
12 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
13 import org.opendaylight.yangtools.concepts.ObjectRegistration;
14 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
15 import org.osgi.framework.Bundle;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.ServiceRegistration;
19 import org.osgi.util.tracker.BundleTracker;
21 public final class Activator implements BundleActivator {
22 private BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker;
23 private SimpleBindingRuntimeContextService service;
24 private ServiceRegistration<?> registration;
27 public void start(final BundleContext context) {
28 // XXX: this will use thread-context class loader, which is probably appropriate
29 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
31 service = new SimpleBindingRuntimeContextService(context, moduleInfoBackedContext, moduleInfoBackedContext);
33 final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
34 moduleInfoBackedContext, service);
36 final ModuleInfoBundleTracker moduleInfoTracker = new ModuleInfoBundleTracker(registry);
37 moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING
38 | Bundle.STOPPING | Bundle.ACTIVE, moduleInfoTracker);
39 moduleInfoResolvedBundleTracker.open();
40 moduleInfoTracker.finishStart();
43 registration = context.registerService(BindingRuntimeContextService.class, service, null);
47 public void stop(final BundleContext context) {
48 moduleInfoResolvedBundleTracker.close();
50 registration.unregister();