sessionManager proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / MDController.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.core;
10
11 import java.util.Collection;
12 import java.util.List;
13 import java.util.concurrent.Future;
14
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
16 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
17 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import com.google.common.collect.Lists;
22
23 /**
24  * @author mirehak
25  *
26  */
27 public class MDController {
28
29     private static final Logger LOG = LoggerFactory
30             .getLogger(MDController.class);
31
32     private SwitchConnectionProvider switchConnectionProvider;
33
34     /**
35      * @param switchConnectionProvider the switchConnectionProvider to set
36      */
37     public void setSwitchConnectionProvider(
38             SwitchConnectionProvider switchConnectionProvider) {
39         this.switchConnectionProvider = switchConnectionProvider;
40     }
41
42     /**
43      * @param switchConnectionProviderToUnset the switchConnectionProvider to unset
44      */
45     public void unsetSwitchConnectionProvider(
46             SwitchConnectionProvider switchConnectionProviderToUnset) {
47         if (this.switchConnectionProvider == switchConnectionProviderToUnset) {
48             this.switchConnectionProvider = null;
49         }
50     }
51
52     /**
53      * Function called by dependency manager after "init ()" is called and after
54      * the services provided by the class are registered in the service registry
55      *
56      */
57     public void start() {
58         LOG.debug("starting ..");
59         LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
60         // setup handler
61         SwitchConnectionHandler switchConnectionHandler = new SwitchConnectionHandlerImpl();
62         switchConnectionProvider.setSwitchConnectionHandler(switchConnectionHandler);
63         // configure and startup library servers
64         switchConnectionProvider.configure(getConnectionConfiguration());
65         Future<List<Boolean>> srvStarted = switchConnectionProvider.startup();
66     }
67
68     /**
69      * @return wished connections configurations
70      */
71     private static Collection<ConnectionConfiguration> getConnectionConfiguration() {
72         //TODO:: get config from state manager
73         ConnectionConfiguration configuration = ConnectionConfigurationFactory.getDefault();
74         return Lists.newArrayList(configuration);
75     }
76
77     /**
78      * Function called by the dependency manager before the services exported by
79      * the component are unregistered, this will be followed by a "destroy ()"
80      * calls
81      *
82      */
83     public void stop() {
84         LOG.debug("stopping");
85     }
86
87     /**
88      * Function called by the dependency manager when at least one dependency
89      * become unsatisfied or when the component is shutting down because for
90      * example bundle is being stopped.
91      *
92      */
93     public void destroy() {
94         // do nothing
95     }
96
97 }