a8ff077a43d2fa3434c8cf5551df1d68598631b9
[affinity.git] / affinity / implementation / src / main / java / org / opendaylight / affinity / affinity / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Plexxi, 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.affinity.affinity.internal;
10
11 import java.util.Dictionary;
12 import java.util.HashSet;
13 import java.util.Hashtable;
14 import java.util.Set;
15
16 import org.apache.felix.dm.Component;
17 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
18 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
19 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
20 import org.opendaylight.controller.hosttracker.IfIptoHost;
21 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
22 import org.opendaylight.affinity.affinity.IAffinityManager;
23 import org.opendaylight.affinity.affinity.IAffinityManagerAware;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * AffinityManager Bundle Activator
29  *
30  *
31  */
32 public class Activator extends ComponentActivatorAbstractBase {
33     protected static final Logger logger = LoggerFactory
34             .getLogger(Activator.class);
35
36     /**
37      * Function called when the activator starts just after some
38      * initializations are done by the
39      * ComponentActivatorAbstractBase.
40      *
41      */
42     public void init() {
43
44     }
45
46     /**
47      * Function called when the activator stops just before the
48      * cleanup done by ComponentActivatorAbstractBase
49      *
50      */
51     public void destroy() {
52
53     }
54
55     /**
56      * Function that is used to communicate to dependency manager the
57      * list of known implementations for services inside a container
58      *
59      *
60      * @return An array containing all the CLASS objects that will be
61      * instantiated in order to get an fully working implementation
62      * Object
63      */
64     public Object[] getImplementations() {
65         Object[] res = { AffinityManagerImpl.class };
66         return res;
67     }
68
69     /**
70      * Function that is called when configuration of the dependencies
71      * is required.
72      *
73      * @param c dependency manager Component object, used for
74      * configuring the dependencies exported and imported
75      * @param imp Implementation class that is being configured,
76      * needed as long as the same routine can configure multiple
77      * implementations
78      * @param containerName The containerName being configured, this allow
79      * also optional per-container different behavior if needed, usually
80      * should not be the case though.
81      */
82     public void configureInstance(Component c, Object imp, String containerName) {
83         if (imp.equals(AffinityManagerImpl.class)) {
84             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
85             Set<String> propSet = new HashSet<String>();
86             propSet.add("affinitymanager.configSaveEvent");
87             props.put("cachenames", propSet);
88             // export the service
89             c.setInterface(new String[] {
90                     IAffinityManager.class.getName(),
91                     ICacheUpdateAware.class.getName(),
92                     IConfigurationContainerAware.class.getName() }, props);
93
94             // Now lets add a service dependency to make sure the
95             // provider of service exists
96             c.add(createContainerServiceDependency(containerName).setService(
97                     IAffinityManagerAware.class).setCallbacks(
98                     "setAffinityManagerAware", "unsetAffinityManagerAware")
99                     .setRequired(false));
100             c.add(createContainerServiceDependency(containerName).setService(
101                     IClusterContainerServices.class).setCallbacks(
102                     "setClusterContainerService",
103                     "unsetClusterContainerService").setRequired(true));
104             c.add(createContainerServiceDependency(containerName).setService(IfIptoHost.class)
105                   .setCallbacks("setHostTracker", "unsetHostTracker").setRequired(true));
106         }
107     }
108 }