Bug 1029: Remove dead code: samples/clustersession
[controller.git] / opendaylight / adsal / 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
28     /**
29      * Function that is used to communicate to dependency manager the
30      * list of known implementations for services inside a container
31      *
32      *
33      * @return An array containing all the CLASS objects that will be
34      * instantiated in order to get an fully working implementation
35      * Object
36      */
37     public Object[] getImplementations() {
38         Object[] res = { ContainerImpl.class };
39         return res;
40     }
41
42     /**
43      * Function that is called when configuration of the dependencies
44      * is required.
45      *
46      * @param c dependency manager Component object, used for
47      * configuring the dependencies exported and imported
48      * @param imp Implementation class that is being configured,
49      * needed as long as the same routine can configure multiple
50      * implementations
51      * @param containerName The containerName being configured, this allow
52      * also optional per-container different behavior if needed, usually
53      * should not be the case though.
54      */
55     public void configureInstance(Component c, Object imp, String containerName) {
56         if (imp.equals(ContainerImpl.class)) {
57             // export the service
58             c.setInterface(new String[] { IContainer.class.getName() }, null);
59         }
60     }
61
62     /**
63      * Method which tells how many Global implementations are
64      * supported by the bundle. This way we can tune the number of
65      * components created. This components will be created ONLY at the
66      * time of bundle startup and will be destroyed only at time of
67      * bundle destruction, this is the major difference with the
68      * implementation retrieved via getImplementations where all of
69      * them are assumed to be in a container!
70      *
71      *
72      * @return The list of implementations the bundle will support,
73      * in Global version
74      */
75     protected Object[] getGlobalImplementations() {
76         Object[] res = { ContainerManager.class };
77         return res;
78     }
79
80     /**
81      * Configure the dependency for a given instance Global
82      *
83      * @param c Component assigned for this instance, this will be
84      * what will be used for configuration
85      * @param imp implementation to be configured
86      * @param containerName container on which the configuration happens
87      */
88     protected void configureGlobalInstance(Component c, Object imp) {
89         if (imp.equals(ContainerManager.class)) {
90
91             // export the service
92             c.setInterface(new String[] { IContainerManager.class.getName() },
93                     null);
94
95             c.add(createServiceDependency().setService(
96                     IClusterGlobalServices.class).setCallbacks(
97                     "setClusterServices", "unsetClusterServices").setRequired(
98                     true));
99
100             // Key kick-starter for container creation in each component
101             c.add(createServiceDependency().setService(IContainerAware.class)
102                     .setCallbacks("setIContainerAware", "unsetIContainerAware")
103                     .setRequired(false));
104
105             // Optional interface expected to be exported by the
106             // protocol plugins to setup proper filtering based on
107             // slicing events
108             c.add(createServiceDependency()
109                     .setService(IContainerListener.class).setCallbacks(
110                             "setIContainerListener", "unsetIContainerListener")
111                     .setRequired(false));
112         }
113     }
114 }