78b64400c8fcc44acba896397d621243848f9ea4
[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      * Function called when the activator starts just after some
42      * initializations are done by the
43      * ComponentActivatorAbstractBase.
44      *
45      */
46     public void init() {
47     }
48
49     /**
50      * Function called when the activator stops just before the
51      * cleanup done by ComponentActivatorAbstractBase
52      *
53      */
54     public void destroy() {
55     }
56
57     /**
58      * Function that is used to communicate to dependency manager the
59      * list of known implementations for services inside a container
60      *
61      *
62      * @return An array containing all the CLASS objects that will be
63      * instantiated in order to get an fully working implementation
64      * Object
65      */
66     public Object[] getImplementations() {
67         Object[] res = { ConfigurationContainerImpl.class };
68         return res;
69     }
70
71     /**
72      * Function that is called when configuration of the dependencies
73      * is required.
74      *
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
79      * implementations
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.
83      */
84     public void configureInstance(Component c, Object imp, String containerName) {
85         if (imp.equals(ConfigurationContainerImpl.class)) {
86             // export the service
87             c.setInterface(new String[] {
88                     IConfigurationContainerService.class.getName(),
89                     IConfigurationAware.class.getName() }, null);
90
91             c.add(createContainerServiceDependency(containerName).setService(
92                     IConfigurationContainerAware.class).setCallbacks(
93                             "addConfigurationContainerAware",
94                             "removeConfigurationContainerAware").setRequired(false));
95         }
96     }
97
98     /**
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!
106      *
107      *
108      * @return The list of implementations the bundle will support,
109      * in Global version
110      */
111     protected Object[] getGlobalImplementations() {
112         Object[] res = { ConfigurationImpl.class };
113         return res;
114     }
115
116     /**
117      * Configure the dependency for a given instance Global
118      *
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
123      */
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);
130
131             // export the service
132             c.setInterface(
133                     new String[] { IConfigurationService.class.getName(),
134                             ICacheUpdateAware.class.getName()},
135                             props);
136
137             c.add(createServiceDependency().setService(
138                     IClusterGlobalServices.class).setCallbacks(
139                             "setClusterServices", "unsetClusterServices").setRequired(
140                                     true));
141
142             c.add(createServiceDependency().setService(
143                     IConfigurationAware.class).setCallbacks(
144                             "addConfigurationAware", "removeConfigurationAware")
145                             .setRequired(false));
146         }
147     }
148 }