2 * Copyright (c) 2013 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
11 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
12 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
13 import org.osgi.framework.BundleActivator;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceRegistration;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import java.util.Hashtable;
21 import static com.google.common.base.Preconditions.checkState;
23 public class Activator implements BundleActivator, YangStoreServiceTracker.YangStoreTrackerListener {
25 private static final Logger logger = LoggerFactory.getLogger(Activator.class);
27 private BundleContext context;
28 private ServiceRegistration osgiRegistration;
29 private ConfigRegistryLookupThread configRegistryLookup = null;
32 public void start(BundleContext context) throws Exception {
33 this.context = context;
34 YangStoreServiceTracker tracker = new YangStoreServiceTracker(context, this);
39 public void stop(BundleContext context) throws Exception {
40 if (configRegistryLookup != null) {
41 configRegistryLookup.interrupt();
46 public synchronized void onYangStoreAdded(YangStoreService yangStoreService) {
47 checkState(configRegistryLookup == null, "More than one onYangStoreAdded received");
48 configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService);
49 configRegistryLookup.start();
53 public synchronized void onYangStoreRemoved() {
54 configRegistryLookup.interrupt();
55 if (osgiRegistration != null) {
56 osgiRegistration.unregister();
58 osgiRegistration = null;
59 configRegistryLookup = null;
62 private class ConfigRegistryLookupThread extends Thread {
63 private final YangStoreService yangStoreService;
65 private ConfigRegistryLookupThread(YangStoreService yangStoreService) {
66 super("config-registry-lookup");
67 this.yangStoreService = yangStoreService;
72 NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService);
73 logger.debug("Registering into OSGi");
74 osgiRegistration = context.registerService(new String[]{NetconfOperationServiceFactory.class.getName()}, factory,
75 new Hashtable<String, Object>());