support map request serialization TELSDN-378: #close
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / Activator.java
1 /*
2  * Copyright (c) 2013 Contextream, 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.lispflowmapping.implementation;
10
11 import java.util.Dictionary;
12 import java.util.Hashtable;
13
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
16 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
17 import org.opendaylight.lispflowmapping.implementation.dao.ClusterDAOService;
18 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
19 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Main application activator class for registering the dependencies and
25  * initialising the Mapping Service application.
26  * 
27  */
28
29 public class Activator extends ComponentActivatorAbstractBase {
30
31     /*
32      * Logger instance
33      */
34     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
35
36     /**
37      * Function called when the activator starts just after some initializations
38      * are done by the ComponentActivatorAbstractBase.
39      * 
40      */
41     @Override
42     public void init() {
43     }
44
45     /**
46      * Function called when the activator stops just before the cleanup done by
47      * ComponentActivatorAbstractBase
48      * 
49      */
50     @Override
51     public void destroy() {
52     }
53
54     /**
55      * Function that is used to communicate to dependency manager the list of
56      * known implementations for services inside a container
57      * 
58      * 
59      * @return An array containing all the CLASS objects that will be
60      *         instantiated in order to get an fully working implementation
61      *         Object
62      */
63     @Override
64     public Object[] getImplementations() {
65         Object[] res = { LispMappingService.class, ClusterDAOService.class };
66         return res;
67     }
68
69     /**
70      * Function that is called when configuration of the dependencies is
71      * required.
72      * 
73      * @param c
74      *            dependency manager Component object, used for configuring the
75      *            dependencies exported and imported
76      * @param imp
77      *            Implementation class that is being configured, needed as long
78      *            as the same routine can configure multiple implementations
79      * @param containerName
80      *            The containerName being configured, this allow also optional
81      *            per-container different behavior if needed, usually should not
82      *            be the case though.
83      */
84     @Override
85     public void configureInstance(Component c, Object imp, String containerName) {
86         if (imp.equals(LispMappingService.class)) {
87             // export the service
88             Dictionary<String, String> props = new Hashtable<String, String>();
89             props.put("name", "mappingservice");
90             c.setInterface(new String[] { IFlowMapping.class.getName() }, props);
91             c.add(createContainerServiceDependency(containerName).setService(ILispDAO.class).setCallbacks("setLispDao", "unsetLispDao").setRequired(
92                     true));
93         } else if (imp.equals(ClusterDAOService.class)) {
94             // export the service
95             Dictionary<String, String> props = new Hashtable<String, String>();
96             props.put("name", "clusterosgiservice");
97             c.setInterface(new String[] { ILispDAO.class.getName() }, props);
98             c.add(createContainerServiceDependency(containerName).setService(IClusterContainerServices.class).setCallbacks(
99                     "setClusterContainerService", "unsetClusterContainerService").setRequired(true));
100         }
101     }
102
103     /**
104      * Method which tells how many Global implementations are supported by the
105      * bundle. This way we can tune the number of components created. This
106      * components will be created ONLY at the time of bundle startup and will be
107      * destroyed only at time of bundle destruction, this is the major
108      * difference with the implementation retrieved via getImplementations where
109      * all of them are assumed to be in a container !
110      * 
111      * 
112      * @return The list of implementations the bundle will support, in Global
113      *         version
114      */
115     @Override
116     protected Object[] getGlobalImplementations() {
117         return null;
118     }
119
120     /**
121      * Configure the dependency for a given instance Global
122      * 
123      * @param c
124      *            Component assigned for this instance, this will be what will
125      *            be used for configuration
126      * @param imp
127      *            implementation to be configured
128      * @param containerName
129      *            container on which the configuration happens
130      */
131     @Override
132     protected void configureGlobalInstance(Component c, Object imp) {
133
134     }
135 }