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 ServiceRegistration osgiRegistration;
31 public void start(BundleContext context) throws Exception {
32 this.context = context;
33 YangStoreServiceTracker tracker = new YangStoreServiceTracker(context, this);
38 public void stop(BundleContext context) throws Exception {
42 public synchronized void onYangStoreAdded(YangStoreService yangStoreService) {
43 checkState(osgiRegistration == null, "More than one onYangStoreAdded received");
44 NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService);
45 logger.debug("Registering into OSGi");
46 osgiRegistration = context.registerService(new String[]{NetconfOperationServiceFactory.class.getName()}, factory,
47 new Hashtable<String, Object>());
51 public synchronized void onYangStoreRemoved() {
52 osgiRegistration.unregister();
53 osgiRegistration = null;