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