Removed old legacy code and moved parent pom.xml to root
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md;
10
11 import org.apache.felix.dm.Component;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
13 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
14 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
15 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
17 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Openflow protocol plugin Activator
23  */
24 public class Activator extends ComponentActivatorAbstractBase {
25     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
26
27     private OpenflowPluginProvider pluginProvider = new OpenflowPluginProvider();
28
29     /**
30      * Function called when the activator starts just after some initializations
31      * are done by the ComponentActivatorAbstractBase.
32      *
33      */
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     public void destroy() {
43     }
44
45     @Override
46     public void start(BundleContext arg0) {
47         super.start(arg0);
48         pluginProvider.setContext(arg0);
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     public Object[] getImplementations() {
61         Object[] res = {};
62         return res;
63     }
64
65     /**
66      * Function that is called when configuration of the dependencies is
67      * required.
68      *
69      * @param c
70      *            dependency manager Component object, used for configuring the
71      *            dependencies exported and imported
72      * @param imp
73      *            Implementation class that is being configured, needed as long
74      *            as the same routine can configure multiple implementations
75      * @param containerName
76      *            The containerName being configured, this allow also optional
77      *            per-container different behavior if needed, usually should not
78      *            be the case though.
79      */
80     public void configureInstance(Component c, Object imp, String containerName) {
81
82     }
83
84     /**
85      * Function that is used to communicate to dependency manager the list of
86      * known implementations for services that are container independent.
87      *
88      *
89      * @return An array containing all the CLASS objects that will be
90      *         instantiated in order to get an fully working implementation
91      *         Object
92      */
93     public Object[] getGlobalImplementations() {
94         Object[] res = { MDController.class, pluginProvider };
95         return res;
96     }
97
98     /**
99      * Function that is called when configuration of the dependencies is
100      * required.
101      *
102      * @param c
103      *            dependency manager Component object, used for configuring the
104      *            dependencies exported and imported
105      * @param imp
106      *            Implementation class that is being configured, needed as long
107      *            as the same routine can configure multiple implementations
108      */
109     public void configureGlobalInstance(Component c, Object imp) {
110
111          if (imp == pluginProvider) {
112             // c.setInterface(new String[] { IDiscoveryListener.class.getName(),
113             // IContainerListener.class.getName(),
114             // IRefreshInternalProvider.class.getName(),
115             // IInventoryShimExternalListener.class.getName() }, null);
116             c.add(createServiceDependency().setService(BindingAwareBroker.class)
117                     .setCallbacks("setBroker", "unsetBroker").setRequired(true));
118             c.add(createServiceDependency().setService(SwitchConnectionProvider.class)
119                     .setCallbacks("setSwitchConnectionProvider", "unsetSwitchConnectionProvider").setRequired(true));
120             logger.debug("configuring Binding Aware Provider");
121         }
122     }
123
124 }