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.ArrayList;
11 import java.util.List;
12 import org.opendaylight.mdsal.binding.dom.codec.osgi.BindingRuntimeContextService;
13 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
14 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
15 import org.osgi.framework.BundleActivator;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceRegistration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public final class Activator implements BundleActivator {
22 private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
24 private final List<ServiceRegistration<?>> registrations = new ArrayList<>(2);
26 private ModuleInfoBundleTracker bundleTracker = null;
27 private SimpleBindingRuntimeContextService service = null;
30 public void start(final BundleContext context) {
31 LOG.info("Binding-DOM codec starting");
33 // XXX: this will use thread-context class loader, which is probably appropriate
34 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
36 service = new SimpleBindingRuntimeContextService(context, moduleInfoBackedContext, moduleInfoBackedContext);
38 final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
39 moduleInfoBackedContext, service);
41 LOG.debug("Starting Binding-DOM codec bundle tracker");
42 bundleTracker = new ModuleInfoBundleTracker(context, registry);
45 LOG.debug("Starting Binding-DOM runtime context service");
48 LOG.debug("Registering Binding-DOM codec services");
49 registrations.add(context.registerService(BindingRuntimeContextService.class, service, null));
50 registrations.add(context.registerService(ClassLoadingStrategy.class, moduleInfoBackedContext, null));
52 LOG.info("Binding-DOM codec started");
56 public void stop(final BundleContext context) {
57 LOG.info("Binding-DOM codec stopping");
59 LOG.debug("Unregistering Binding-DOM codec services");
60 registrations.forEach(ServiceRegistration::unregister);
61 registrations.clear();
63 LOG.debug("Stopping Binding-DOM codec bundle tracker");
64 bundleTracker.close();
66 LOG.debug("Stoping Binding-DOM runtime context service");
69 LOG.info("Binding-DOM codec stopped");