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