Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / 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.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;
28
29 /**
30  * @file Activator.java
31  *
32  * @brief Component Activator for ConfigurationService Management.
33  *
34  *
35  *
36  */
37 public class Activator extends ComponentActivatorAbstractBase {
38     protected static final Logger logger = LoggerFactory
39             .getLogger(Activator.class);
40
41
42     /**
43      * Function that is used to communicate to dependency manager the
44      * list of known implementations for services inside a container
45      *
46      *
47      * @return An array containing all the CLASS objects that will be
48      * instantiated in order to get an fully working implementation
49      * Object
50      */
51     @Override
52     public Object[] getImplementations() {
53         Object[] res = { ContainerConfigurationService.class };
54         return res;
55     }
56
57     /**
58      * Function that is called when configuration of the dependencies
59      * is required.
60      *
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
65      * implementations
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.
69      */
70     @Override
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);
77
78             // export the service
79             c.setInterface(
80                     new String[] { IConfigurationContainerService.class.getName(), IConfigurationAware.class.getName(),
81                             ICacheUpdateAware.class.getName() }, props);
82
83             c.add(createContainerServiceDependency(containerName).setService(
84                     IConfigurationContainerAware.class).setCallbacks(
85                             "addConfigurationContainerAware",
86                             "removeConfigurationContainerAware").setRequired(false));
87
88             c.add(createContainerServiceDependency(containerName).setService(IClusterContainerServices.class)
89                     .setCallbacks("setClusterServices", "unsetClusterServices").setRequired(true));
90         }
91     }
92
93     /**
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!
101      *
102      *
103      * @return The list of implementations the bundle will support,
104      * in Global version
105      */
106     @Override
107     protected Object[] getGlobalImplementations() {
108         Object[] res = { ConfigurationService.class };
109         return res;
110     }
111
112     /**
113      * Configure the dependency for a given instance Global
114      *
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
119      */
120     @Override
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);
127
128             // export the service
129             c.setInterface(
130                     new String[] { IConfigurationService.class.getName(),
131                             ICacheUpdateAware.class.getName() }, props);
132
133             c.add(createServiceDependency().setService(
134                     IClusterGlobalServices.class).setCallbacks(
135                             "setClusterServices", "unsetClusterServices").setRequired(
136                                     true));
137
138             c.add(createServiceDependency().setService(
139                     IConfigurationAware.class).setCallbacks(
140                             "addConfigurationAware", "removeConfigurationAware")
141                             .setRequired(false));
142         }
143     }
144 }