Fixed for bug : 1171 - issue while creating subnet
[controller.git] / opendaylight / md-sal / remoterpc-routingtable / implementation / src / main / java / org / opendaylight / controller / sal / connector / remoterpc / impl / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.sal.connector.remoterpc.impl;
10
11 import org.apache.felix.dm.Component;
12 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
13 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
14 import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
15 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
16 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 import java.util.Dictionary;
21 import java.util.HashSet;
22 import java.util.Hashtable;
23 import java.util.Set;
24
25 /**
26  * @author: syedbahm
27  */
28 public class Activator extends ComponentActivatorAbstractBase {
29
30     protected static final Logger logger = LoggerFactory
31             .getLogger(Activator.class);
32     private static final String CACHE_UPDATE_AWARE_REGISTRY_KEY = "cachenames" ;
33
34
35     /**
36      * Method which tells how many Global implementations are
37      * supported by the bundle. This way we can tune the number of
38      * components created. This components will be created ONLY at the
39      * time of bundle startup and will be destroyed only at time of
40      * bundle destruction, this is the major difference with the
41      * implementation retrieved via getImplementations where all of
42      * them are assumed to be in a container!
43      *
44      *
45      * @return The list of implementations the bundle will support,
46      * in Global version
47      */
48
49     @Override
50     protected Object[] getGlobalImplementations(){
51         logger.debug("Calling getGlobalImplementations to return:", RoutingTableImpl.class);
52         return new Object[] {
53                 RoutingTableImpl.class
54         };
55     }
56
57     /**
58      * Configure the dependency for a given instance Global
59      *
60      * @param c Component assigned for this instance, this will be
61      * what will be used for configuration
62      * @param imp implementation to be configured
63      *
64      */
65     @Override
66     protected void configureGlobalInstance(Component c, Object imp){
67         if (imp.equals(RoutingTableImpl.class)) {
68             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
69             Set<String> propSet = new HashSet<String>();
70             propSet.add(RoutingTableImpl.GLOBALRPC_CACHE);
71             propSet.add(RoutingTableImpl.RPC_CACHE);
72             props.put(CACHE_UPDATE_AWARE_REGISTRY_KEY, propSet);
73
74             c.setInterface(new String[] { RoutingTable.class.getName(),ICacheUpdateAware.class.getName()  }, props);
75             logger.debug("configureGlobalInstance adding dependency:", IClusterGlobalServices.class);
76
77
78             // RouteChangeListener services will be none or many so the
79             // dependency is optional
80             c.add(createServiceDependency()
81                     .setService(RouteChangeListener.class)
82                     .setCallbacks("setRouteChangeListener", "unsetRouteChangeListener")
83                     .setRequired(false));
84
85             //dependency is required as it provides us the caching support
86             c.add(createServiceDependency().setService(
87                     IClusterGlobalServices.class).setCallbacks(
88                     "setClusterGlobalServices",
89                     "unsetClusterGlobalServices").setRequired(true));
90
91         }
92     }
93
94
95 }