Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / containermanager / 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.eclipse.osgi.framework.console.CommandProvider;
13 import java.util.Dictionary;
14 import java.util.HashSet;
15 import java.util.Set;
16 import java.util.Hashtable;
17 import org.opendaylight.controller.containermanager.IContainerManager;
18 import org.apache.felix.dm.Component;
19 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
20 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
21 import org.opendaylight.controller.configuration.IConfigurationAware;
22 import org.opendaylight.controller.configuration.IConfigurationService;
23 import org.opendaylight.controller.containermanager.IContainerAuthorization;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.opendaylight.controller.sal.core.IContainer;
26 import org.opendaylight.controller.sal.core.IContainerAware;
27 import org.opendaylight.controller.sal.core.IContainerListener;
28 import org.opendaylight.controller.sal.core.IContainerLocalListener;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33 public class Activator extends ComponentActivatorAbstractBase {
34     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
35
36
37     /**
38      * Function that is used to communicate to dependency manager the list of
39      * known implementations for containerd-services
40      *
41      *
42      * @return An array containing all the CLASS objects that will be
43      *         instantiated in order to get an fully working implementation
44      *         Object
45      */
46     @Override
47     public Object[] getImplementations() {
48         Object[] res = { ContainerImpl.class };
49         return res;
50     }
51
52     /**
53      * Function that is called when configuration of the dependencies is
54      * required.
55      *
56      * @param c
57      *            dependency manager Component object, used for configuring the
58      *            dependencies exported and imported
59      * @param imp
60      *            Implementation class that is being configured, needed as long
61      *            as the same routine can configure multiple implementations
62      * @param containerName
63      *            The containername being configured, this allow also optional
64      *            per-container different behavior if needed, usually should not be
65      *            the case though.
66      */
67     @Override
68     public void configureInstance(Component c, Object imp, String containerName) {
69         if (imp.equals(ContainerImpl.class)) {
70             // export the service
71             c.setInterface(new String[] { IContainer.class.getName() }, null);
72
73             // private interface exported by ContainerManager to retrieve
74             // internal data, this is mandatory to implement the
75             // IContainer functionality
76             c.add(createServiceDependency().setService(IContainerInternal.class)
77                     .setCallbacks("setIContainerInternal", "unsetIContainerInternal")
78                     .setRequired(true));
79         }
80     }
81
82     /**
83      * Method which tells how many NON-containerd implementations are supported by
84      * the bundle. This way we can tune the number of components created. This
85      * components will be created ONLY at the time of bundle startup and will be
86      * destroyed only at time of bundle destruction, this is the major
87      * difference with the implementation retrieved via getImplementations where
88      * all of them are assumed to be containerd!
89      *
90      *
91      * @return The list of implementations the bundle will support, in
92      *         non-containerd version
93      */
94     @Override
95     protected Object[] getGlobalImplementations() {
96         Object[] res = { ContainerManager.class };
97         return res;
98     }
99
100     /**
101      * Configure the dependency for a given instance non-containerd
102      *
103      * @param c
104      *            Component assigned for this instance, this will be what will
105      *            be used for configuration
106      * @param imp
107      *            implementation to be configured
108      * @param containerName
109      *            container on which the configuration happens
110      */
111     @Override
112     protected void configureGlobalInstance(Component c, Object imp) {
113         if (imp.equals(ContainerManager.class)) {
114             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
115             Set<String> propSet = new HashSet<String>();
116             propSet.add("containermgr.event.containerChange");
117             props.put("cachenames", propSet);
118
119             // export the service
120             c.setInterface(
121                     new String[] { IContainerManager.class.getName(),
122                             IContainerManager.class.getName(),
123                             IConfigurationAware.class.getName(),
124                             CommandProvider.class.getName(),
125                             IContainerInternal.class.getName(),
126                             IContainerAuthorization.class.getName(),
127                             ICacheUpdateAware.class.getName()}, props);
128
129             c.add(createServiceDependency()
130                     .setService(IClusterGlobalServices.class)
131                     .setCallbacks("setClusterServices", "unsetClusterServices")
132                     .setRequired(true));
133
134             c.add(createServiceDependency().setService(
135                     IConfigurationService.class).setCallbacks(
136                     "setConfigurationService",
137                     "unsetConfigurationService").setRequired(true));
138
139             // Key kick-starter for container creation in each component
140             c.add(createServiceDependency().setService(IContainerAware.class)
141                     .setCallbacks("setIContainerAware", "unsetIContainerAware")
142                     .setRequired(false));
143
144             // Optional interface expected to be exported by the
145             // protocol plugins to setup proper filtering based on
146             // slicing events
147             c.add(createServiceDependency()
148                     .setService(IContainerListener.class)
149                     .setCallbacks("setIContainerListener", "unsetIContainerListener")
150                     .setRequired(false));
151
152             // Interface expected to be exported by the Functional Modules
153             c.add(createServiceDependency()
154                     .setService(IContainerLocalListener.class)
155                     .setCallbacks("setIContainerLocalListener", "unsetIContainerLocalListener")
156                     .setRequired(false));
157         }
158     }
159 }