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