871fd0704e42848259de19fa279859fd597e92ae
[controller.git] / opendaylight / configuration / implementation / src / main / java / org / opendaylight / controller / configuration / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.configuration.internal;
11
12 import java.util.Dictionary;
13 import java.util.HashSet;
14 import java.util.Hashtable;
15 import java.util.Set;
16
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;
27
28 /**
29  * @file Activator.java
30  *
31  * @brief Component Activator for Configuration Management.
32  *
33  *
34  *
35  */
36 public class Activator extends ComponentActivatorAbstractBase {
37     protected static final Logger logger = LoggerFactory
38             .getLogger(Activator.class);
39
40
41     /**
42      * Function that is used to communicate to dependency manager the
43      * list of known implementations for services inside a container
44      *
45      *
46      * @return An array containing all the CLASS objects that will be
47      * instantiated in order to get an fully working implementation
48      * Object
49      */
50     public Object[] getImplementations() {
51         Object[] res = { ConfigurationContainerImpl.class };
52         return res;
53     }
54
55     /**
56      * Function that is called when configuration of the dependencies
57      * is required.
58      *
59      * @param c dependency manager Component object, used for
60      * configuring the dependencies exported and imported
61      * @param imp Implementation class that is being configured,
62      * needed as long as the same routine can configure multiple
63      * implementations
64      * @param containerName The containerName being configured, this allow
65      * also optional per-container different behavior if needed, usually
66      * should not be the case though.
67      */
68     public void configureInstance(Component c, Object imp, String containerName) {
69         if (imp.equals(ConfigurationContainerImpl.class)) {
70             // export the service
71             c.setInterface(new String[] {
72                     IConfigurationContainerService.class.getName(),
73                     IConfigurationAware.class.getName() }, null);
74
75             c.add(createContainerServiceDependency(containerName).setService(
76                     IConfigurationContainerAware.class).setCallbacks(
77                             "addConfigurationContainerAware",
78                             "removeConfigurationContainerAware").setRequired(false));
79         }
80     }
81
82     /**
83      * Method which tells how many Global implementations are
84      * supported by the bundle. This way we can tune the number of
85      * components created. This components will be created ONLY at the
86      * time of bundle startup and will be destroyed only at time of
87      * bundle destruction, this is the major difference with the
88      * implementation retrieved via getImplementations where all of
89      * them are assumed to be in a container!
90      *
91      *
92      * @return The list of implementations the bundle will support,
93      * in Global version
94      */
95     protected Object[] getGlobalImplementations() {
96         Object[] res = { ConfigurationImpl.class };
97         return res;
98     }
99
100     /**
101      * Configure the dependency for a given instance Global
102      *
103      * @param c Component assigned for this instance, this will be
104      * what will be used for configuration
105      * @param imp implementation to be configured
106      * @param containerName container on which the configuration happens
107      */
108     protected void configureGlobalInstance(Component c, Object imp) {
109         if (imp.equals(ConfigurationImpl.class)) {
110             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
111             Set<String> propSet = new HashSet<String>();
112             propSet.add("config.event.save");
113             props.put("cachenames", propSet);
114
115             // export the service
116             c.setInterface(
117                     new String[] { IConfigurationService.class.getName(),
118                             ICacheUpdateAware.class.getName()},
119                             props);
120
121             c.add(createServiceDependency().setService(
122                     IClusterGlobalServices.class).setCallbacks(
123                             "setClusterServices", "unsetClusterServices").setRequired(
124                                     true));
125
126             c.add(createServiceDependency().setService(
127                     IConfigurationAware.class).setCallbacks(
128                             "addConfigurationAware", "removeConfigurationAware")
129                             .setRequired(false));
130         }
131     }
132 }