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