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