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.binding.runtime.api.ClassLoadingStrategy;
13 import org.opendaylight.binding.runtime.spi.GeneratedClassLoadingStrategy;
14 import org.opendaylight.binding.runtime.spi.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;
29 public void start(final BundleContext context) {
30 LOG.info("Binding-DOM codec starting");
32 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(
33 // FIXME: This is the fallback strategy, it should not be needed
34 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
36 final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
37 moduleInfoBackedContext);
39 LOG.debug("Starting Binding-DOM codec bundle tracker");
40 bundleTracker = new ModuleInfoBundleTracker(context, registry);
43 LOG.debug("Registering Binding-DOM codec services");
44 registrations.add(context.registerService(ClassLoadingStrategy.class, moduleInfoBackedContext, null));
46 LOG.info("Binding-DOM codec started");
50 public void stop(final BundleContext context) {
51 LOG.info("Binding-DOM codec stopping");
53 LOG.debug("Unregistering Binding-DOM codec services");
54 registrations.forEach(ServiceRegistration::unregister);
55 registrations.clear();
57 LOG.debug("Stopping Binding-DOM codec bundle tracker");
58 bundleTracker.close();
60 LOG.info("Binding-DOM codec stopped");