35b51466795c060c0dfc0112ea8826917edda2ce
[controller.git] / opendaylight / clustering / services_implementation / src / main / java / org / opendaylight / controller / clustering / services_implementation / 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.clustering.services_implementation.internal;
11
12 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
13 import org.opendaylight.controller.sal.core.IContainerAware;
14
15 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
16 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
17 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
18 import org.opendaylight.controller.clustering.services.IClusterServices;
19 import org.opendaylight.controller.clustering.services.ICoordinatorChangeAware;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.apache.felix.dm.Component;
23
24 public class Activator extends ComponentActivatorAbstractBase {
25     protected static final Logger logger = LoggerFactory
26             .getLogger(Activator.class);
27
28
29
30     /**
31      * Function that is used to communicate to dependency manager the
32      * list of known implementations for services inside a container
33      *
34      *
35      * @return An array containing all the CLASS objects that will be
36      * instantiated in order to get an fully working implementation
37      * Object
38      */
39     @Override
40     public Object[] getGlobalImplementations() {
41         Object[] res = { ClusterManager.class, ClusterGlobalManager.class, ClusterManagerCLI.class };
42         return res;
43     }
44
45     /**
46      * Function that is used to communicate to dependency manager the
47      * list of known implementations for services inside a container
48      *
49      *
50      * @return An array containing all the CLASS objects that will be
51      * instantiated in order to get an fully working implementation
52      * Object
53      */
54     @Override
55     public Object[] getImplementations() {
56         Object[] res = { ClusterContainerManager.class };
57         return res;
58     }
59
60     /**
61      * Function that is called when configuration of the dependencies
62      * is required.
63      *
64      * @param c dependency manager Component object, used for
65      * configuring the dependencies exported and imported
66      * @param imp Implementation class that is being configured,
67      * needed as long as the same routine can configure multiple
68      * implementations
69      * @param containerName The containerName being configured, this allow
70      * also optional per-container different behavior if needed, usually
71      * should not be the case though.
72      */
73     @Override
74     public void configureInstance(Component c, Object imp, String containerName) {
75         if (imp.equals(ClusterContainerManager.class)) {
76             c.setInterface(new String[] { IClusterContainerServices.class.getName() },
77                            null);
78
79             c.add(createServiceDependency()
80                   .setService(IClusterServices.class)
81                   .setCallbacks("setClusterService", "unsetClusterService")
82                   .setRequired(true));
83
84             // CacheUpdate services will be none or many so the
85             // dependency is optional
86             c.add(createContainerServiceDependency(containerName)
87                   .setService(ICacheUpdateAware.class)
88                   .setCallbacks("setCacheUpdateAware", "unsetCacheUpdateAware")
89                   .setRequired(false));
90
91             // Coordinator change event can be one or many so
92             // dependency is optional
93             c.add(createContainerServiceDependency(containerName)
94                   .setService(ICoordinatorChangeAware.class)
95                   .setCallbacks("setCoordinatorChangeAware", "unsetCoordinatorChangeAware")
96                   .setRequired(false));
97         }
98     }
99
100     /**
101      * Function that is called when configuration of the dependencies
102      * is required.
103      *
104      * @param c dependency manager Component object, used for
105      * configuring the dependencies exported and imported
106      * @param imp Implementation class that is being configured,
107      * needed as long as the same routine can configure multiple
108      * implementations
109      */
110     @Override
111     public void configureGlobalInstance(Component c, Object imp) {
112         if (imp.equals(ClusterManager.class)) {
113             // export the service for Apps and Plugins
114             c.setInterface(new String[] { IClusterServices.class.getName(), IContainerAware.class.getName() }, null);
115         }
116
117         if (imp.equals(ClusterGlobalManager.class)) {
118             c.setInterface(new String[] { IClusterGlobalServices.class.getName() }, null);
119
120             c.add(createServiceDependency()
121                   .setService(IClusterServices.class)
122                   .setCallbacks("setClusterService", "unsetClusterService")
123                   .setRequired(true));
124
125             // CacheUpdate services will be none or many so the
126             // dependency is optional
127             c.add(createServiceDependency()
128                   .setService(ICacheUpdateAware.class)
129                   .setCallbacks("setCacheUpdateAware", "unsetCacheUpdateAware")
130                   .setRequired(false));
131
132             // Coordinator change event can be one or many so
133             // dependency is optional
134             c.add(createServiceDependency()
135                   .setService(ICoordinatorChangeAware.class)
136                   .setCallbacks("setCoordinatorChangeAware", "unsetCoordinatorChangeAware")
137                   .setRequired(false));
138         }
139     }
140 }