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