5ebbfe2ea8cfb26dd6523b54acc147709b56bf2e
[controller.git] / opendaylight / connectionmanager / implementation / src / main / java / org / opendaylight / controller / connectionmanager / 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.connectionmanager.internal;
11
12 import java.util.Dictionary;
13 import java.util.HashSet;
14 import java.util.Hashtable;
15 import java.util.Set;
16
17 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
18 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
19 import org.opendaylight.controller.clustering.services.ICoordinatorChangeAware;
20 import org.opendaylight.controller.connectionmanager.IConnectionManager;
21 import org.opendaylight.controller.sal.connection.IConnectionListener;
22 import org.opendaylight.controller.sal.connection.IConnectionService;
23 import org.apache.felix.dm.Component;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
27 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
28
29 public class Activator extends ComponentActivatorAbstractBase {
30     protected static final Logger logger = LoggerFactory
31             .getLogger(Activator.class);
32
33     /**
34      * Function called when the activator starts just after some
35      * initializations are done by the
36      * ComponentActivatorAbstractBase.
37      *
38      */
39     public void init() {
40     }
41
42     /**
43      * Function called when the activator stops just before the
44      * cleanup done by ComponentActivatorAbstractBase
45      *
46      */
47     public void destroy() {
48     }
49
50     /**
51      * Method which tells how many Global implementations are
52      * supported by the bundle. This way we can tune the number of
53      * components created. This components will be created ONLY at the
54      * time of bundle startup and will be destroyed only at time of
55      * bundle destruction, this is the major difference with the
56      * implementation retrieved via getImplementations where all of
57      * them are assumed to be in a container!
58      *
59      *
60      * @return The list of implementations the bundle will support,
61      * in Global version
62      */
63     protected Object[] getGlobalImplementations() {
64         Object[] res = { ConnectionManager.class };
65         return res;
66     }
67
68     /**
69      * Configure the dependency for a given instance Global
70      *
71      * @param c Component assigned for this instance, this will be
72      * what will be used for configuration
73      * @param imp implementation to be configured
74      * @param containerName container on which the configuration happens
75      */
76     protected void configureGlobalInstance(Component c, Object imp) {
77         if (imp.equals(ConnectionManager.class)) {
78             Dictionary<String, Object> props = new Hashtable<String, Object>();
79             Set<String> propSet = new HashSet<String>();
80             propSet.add("connectionmanager.nodeconnections");
81             props.put("cachenames", propSet);
82             props.put("scope", "Global");
83
84             // export the service
85             c.setInterface(new String[] { IConnectionManager.class.getName(),
86                                           IConnectionListener.class.getName(),
87                                           ICoordinatorChangeAware.class.getName(),
88                                           IListenInventoryUpdates.class.getName(),
89                                           ICacheUpdateAware.class.getName()},
90                                           props);
91
92             c.add(createServiceDependency()
93                     .setService(IClusterGlobalServices.class)
94                     .setCallbacks("setClusterServices", "unsetClusterServices")
95                     .setRequired(true));
96
97             c.add(createServiceDependency().setService(IConnectionService.class)
98                     .setCallbacks("setConnectionService", "unsetConnectionService")
99                     .setRequired(true));
100         }
101     }
102 }