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