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.IClusterContainerServices;
20 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
21 import org.opendaylight.controller.configuration.IConfigurationAware;
22 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
23 import org.opendaylight.controller.configuration.IConfigurationContainerService;
24 import org.opendaylight.controller.configuration.IConfigurationService;
25 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * @file Activator.java
32 * @brief Component Activator for ConfigurationService Management.
37 public class Activator extends ComponentActivatorAbstractBase {
38 protected static final Logger logger = LoggerFactory
39 .getLogger(Activator.class);
43 * Function that is used to communicate to dependency manager the
44 * list of known implementations for services inside a container
47 * @return An array containing all the CLASS objects that will be
48 * instantiated in order to get an fully working implementation
52 public Object[] getImplementations() {
53 Object[] res = { ContainerConfigurationService.class };
58 * Function that is called when configuration of the dependencies
61 * @param c dependency manager Component object, used for
62 * configuring the dependencies exported and imported
63 * @param imp Implementation class that is being configured,
64 * needed as long as the same routine can configure multiple
66 * @param containerName The containerName being configured, this allow
67 * also optional per-container different behavior if needed, usually
68 * should not be the case though.
71 public void configureInstance(Component c, Object imp, String containerName) {
72 if (imp.equals(ContainerConfigurationService.class)) {
73 Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
74 Set<String> propSet = new HashSet<String>();
75 propSet.add(ContainerConfigurationService.CONTAINER_SAVE_EVENT_CACHE);
76 props.put("cachenames", propSet);
80 new String[] { IConfigurationContainerService.class.getName(), IConfigurationAware.class.getName(),
81 ICacheUpdateAware.class.getName() }, props);
83 c.add(createContainerServiceDependency(containerName).setService(
84 IConfigurationContainerAware.class).setCallbacks(
85 "addConfigurationContainerAware",
86 "removeConfigurationContainerAware").setRequired(false));
88 c.add(createContainerServiceDependency(containerName).setService(IClusterContainerServices.class)
89 .setCallbacks("setClusterServices", "unsetClusterServices").setRequired(true));
94 * Method which tells how many Global implementations are
95 * supported by the bundle. This way we can tune the number of
96 * components created. This components will be created ONLY at the
97 * time of bundle startup and will be destroyed only at time of
98 * bundle destruction, this is the major difference with the
99 * implementation retrieved via getImplementations where all of
100 * them are assumed to be in a container!
103 * @return The list of implementations the bundle will support,
107 protected Object[] getGlobalImplementations() {
108 Object[] res = { ConfigurationService.class };
113 * Configure the dependency for a given instance Global
115 * @param c Component assigned for this instance, this will be
116 * what will be used for configuration
117 * @param imp implementation to be configured
118 * @param containerName container on which the configuration happens
121 protected void configureGlobalInstance(Component c, Object imp) {
122 if (imp.equals(ConfigurationService.class)) {
123 Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
124 Set<String> propSet = new HashSet<String>();
125 propSet.add(ConfigurationService.SAVE_EVENT_CACHE);
126 props.put("cachenames", propSet);
128 // export the service
130 new String[] { IConfigurationService.class.getName(),
131 ICacheUpdateAware.class.getName()},
134 c.add(createServiceDependency().setService(
135 IClusterGlobalServices.class).setCallbacks(
136 "setClusterServices", "unsetClusterServices").setRequired(
139 c.add(createServiceDependency().setService(
140 IConfigurationAware.class).setCallbacks(
141 "addConfigurationAware", "removeConfigurationAware")
142 .setRequired(false));