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