Merge "Declare a property for commons-lang version in poms and use it."
[controller.git] / opendaylight / containermanager / it.implementation / src / main / java / org / opendaylight / controller / containermanager / 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.containermanager.internal;
11
12 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
13 import org.opendaylight.controller.containermanager.IContainerManager;
14 import org.opendaylight.controller.sal.core.IContainerAware;
15 import org.opendaylight.controller.sal.core.IContainer;
16 import org.opendaylight.controller.sal.core.IContainerListener;
17 import org.apache.felix.dm.Component;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
21
22 public class Activator extends ComponentActivatorAbstractBase {
23     protected static final Logger logger = LoggerFactory
24             .getLogger(Activator.class);
25
26     /**
27      * Function called when the activator starts just after some
28      * initializations are done by the
29      * ComponentActivatorAbstractBase.
30      *
31      */
32     public void init() {
33     }
34
35     /**
36      * Function called when the activator stops just before the
37      * cleanup done by ComponentActivatorAbstractBase
38      *
39      */
40     public void destroy() {
41     }
42
43     /**
44      * Function that is used to communicate to dependency manager the
45      * list of known implementations for services inside a container
46      *
47      *
48      * @return An array containing all the CLASS objects that will be
49      * instantiated in order to get an fully working implementation
50      * Object
51      */
52     public Object[] getImplementations() {
53         Object[] res = { ContainerImpl.class };
54         return res;
55     }
56
57     /**
58      * Function that is called when configuration of the dependencies
59      * is required.
60      *
61      * @param c dependency manager Component object, used for
62      * configuring the dependencies exported and imported
63      * @param imp Implementation class that is being configured,
64      * needed as long as the same routine can configure multiple
65      * implementations
66      * @param containerName The containerName being configured, this allow
67      * also optional per-container different behavior if needed, usually
68      * should not be the case though.
69      */
70     public void configureInstance(Component c, Object imp, String containerName) {
71         if (imp.equals(ContainerImpl.class)) {
72             // export the service
73             c.setInterface(new String[] { IContainer.class.getName() }, null);
74         }
75     }
76
77     /**
78      * Method which tells how many Global implementations are
79      * supported by the bundle. This way we can tune the number of
80      * components created. This components will be created ONLY at the
81      * time of bundle startup and will be destroyed only at time of
82      * bundle destruction, this is the major difference with the
83      * implementation retrieved via getImplementations where all of
84      * them are assumed to be in a container!
85      *
86      *
87      * @return The list of implementations the bundle will support,
88      * in Global version
89      */
90     protected Object[] getGlobalImplementations() {
91         Object[] res = { ContainerManager.class };
92         return res;
93     }
94
95     /**
96      * Configure the dependency for a given instance Global
97      *
98      * @param c Component assigned for this instance, this will be
99      * what will be used for configuration
100      * @param imp implementation to be configured
101      * @param containerName container on which the configuration happens
102      */
103     protected void configureGlobalInstance(Component c, Object imp) {
104         if (imp.equals(ContainerManager.class)) {
105
106             // export the service
107             c.setInterface(new String[] { IContainerManager.class.getName() },
108                     null);
109
110             c.add(createServiceDependency().setService(
111                     IClusterGlobalServices.class).setCallbacks(
112                     "setClusterServices", "unsetClusterServices").setRequired(
113                     true));
114
115             // Key kick-starter for container creation in each component
116             c.add(createServiceDependency().setService(IContainerAware.class)
117                     .setCallbacks("setIContainerAware", "unsetIContainerAware")
118                     .setRequired(false));
119
120             // Optional interface expected to be exported by the
121             // protocol plugins to setup proper filtering based on
122             // slicing events
123             c.add(createServiceDependency()
124                     .setService(IContainerListener.class).setCallbacks(
125                             "setIContainerListener", "unsetIContainerListener")
126                     .setRequired(false));
127         }
128     }
129 }