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