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