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.persist.impl.osgi;
11 import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider;
12 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
13 import org.opendaylight.controller.netconf.persist.impl.PersisterImpl;
14 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
15 import org.osgi.framework.BundleActivator;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import javax.management.MBeanServer;
21 import java.lang.management.ManagementFactory;
22 import java.net.InetSocketAddress;
24 public class ConfigPersisterActivator implements BundleActivator {
26 private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterActivator.class);
28 private final static MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
30 private ConfigPersisterNotificationHandler configPersisterNotificationHandler;
32 private Thread initializationThread;
34 private static final String NETCONF_CONFIG_PERSISTER_PREFIX = "netconf.config.persister.";
35 public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX = "storageAdapterClass";
38 public void start(final BundleContext context) throws Exception {
39 logger.debug("ConfigPersister starting");
41 PropertiesProvider propertiesProvider = new PropertiesProvider() {
43 public String getProperty(String key) {
44 return context.getProperty(getFullKeyForReporting(key));
48 public String getFullKeyForReporting(String key) {
49 return NETCONF_CONFIG_PERSISTER_PREFIX + key;
53 PersisterImpl persister = PersisterImpl.createFromProperties(propertiesProvider);
55 InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context,
56 "Netconf is not configured, persister is not operational");
57 configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address,
60 // offload initialization to another thread in order to stop blocking activator
61 Runnable initializationRunnable = new Runnable() {
65 configPersisterNotificationHandler.init();
66 } catch (InterruptedException e) {
67 logger.info("Interrupted while waiting for netconf connection");
71 initializationThread = new Thread(initializationRunnable, "ConfigPersister-registrator");
72 initializationThread.start();
76 public void stop(BundleContext context) throws Exception {
77 initializationThread.interrupt();
78 configPersisterNotificationHandler.close();