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