3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.configuration.internal;
12 import java.util.Dictionary;
13 import java.util.HashSet;
14 import java.util.Hashtable;
17 import org.apache.felix.dm.Component;
18 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
19 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
20 import org.opendaylight.controller.configuration.IConfigurationAware;
21 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
22 import org.opendaylight.controller.configuration.IConfigurationContainerService;
23 import org.opendaylight.controller.configuration.IConfigurationService;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * @file Activator.java
31 * @brief Component Activator for Configuration Management.
36 public class Activator extends ComponentActivatorAbstractBase {
37 protected static final Logger logger = LoggerFactory
38 .getLogger(Activator.class);
41 * Function called when the activator starts just after some
42 * initializations are done by the
43 * ComponentActivatorAbstractBase.
50 * Function called when the activator stops just before the
51 * cleanup done by ComponentActivatorAbstractBase
54 public void destroy() {
58 * Function that is used to communicate to dependency manager the
59 * list of known implementations for services inside a container
62 * @return An array containing all the CLASS objects that will be
63 * instantiated in order to get an fully working implementation
66 public Object[] getImplementations() {
67 Object[] res = { ConfigurationContainerImpl.class };
72 * Function that is called when configuration of the dependencies
75 * @param c dependency manager Component object, used for
76 * configuring the dependencies exported and imported
77 * @param imp Implementation class that is being configured,
78 * needed as long as the same routine can configure multiple
80 * @param containerName The containerName being configured, this allow
81 * also optional per-container different behavior if needed, usually
82 * should not be the case though.
84 public void configureInstance(Component c, Object imp, String containerName) {
85 if (imp.equals(ConfigurationContainerImpl.class)) {
87 c.setInterface(new String[] {
88 IConfigurationContainerService.class.getName(),
89 IConfigurationAware.class.getName() }, null);
91 c.add(createContainerServiceDependency(containerName).setService(
92 IConfigurationContainerAware.class).setCallbacks(
93 "addConfigurationContainerAware",
94 "removeConfigurationContainerAware").setRequired(false));
99 * Method which tells how many Global implementations are
100 * supported by the bundle. This way we can tune the number of
101 * components created. This components will be created ONLY at the
102 * time of bundle startup and will be destroyed only at time of
103 * bundle destruction, this is the major difference with the
104 * implementation retrieved via getImplementations where all of
105 * them are assumed to be in a container!
108 * @return The list of implementations the bundle will support,
111 protected Object[] getGlobalImplementations() {
112 Object[] res = { ConfigurationImpl.class };
117 * Configure the dependency for a given instance Global
119 * @param c Component assigned for this instance, this will be
120 * what will be used for configuration
121 * @param imp implementation to be configured
122 * @param containerName container on which the configuration happens
124 protected void configureGlobalInstance(Component c, Object imp) {
125 if (imp.equals(ConfigurationImpl.class)) {
126 Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
127 Set<String> propSet = new HashSet<String>();
128 propSet.add("config.event.save");
129 props.put("cachenames", propSet);
131 // export the service
133 new String[] { IConfigurationService.class.getName(),
134 ICacheUpdateAware.class.getName()},
137 c.add(createServiceDependency().setService(
138 IClusterGlobalServices.class).setCallbacks(
139 "setClusterServices", "unsetClusterServices").setRequired(
142 c.add(createServiceDependency().setService(
143 IConfigurationAware.class).setCallbacks(
144 "addConfigurationAware", "removeConfigurationAware")
145 .setRequired(false));