Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / FlowProgrammerNotifier.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.controller.protocol_plugin.openflow.internal;
10
11 import org.apache.felix.dm.Component;
12 import org.opendaylight.controller.protocol_plugin.openflow.IFlowProgrammerNotifier;
13 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.flowprogrammer.Flow;
16 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Flow Programmer Notifier class for relaying asynchronous messages received
22  * from the network node to the listeners on the proper container
23  */
24 public class FlowProgrammerNotifier implements IFlowProgrammerNotifier {
25     protected static final Logger logger = LoggerFactory
26             .getLogger(FlowProgrammerNotifier.class);
27     private IPluginOutFlowProgrammerService salNotifier;
28     private IPluginOutConnectionService connectionOutService;
29
30     public FlowProgrammerNotifier() {
31         salNotifier = null;
32     }
33
34     void init(Component c) {
35         logger.debug("INIT called!");
36     }
37
38     /**
39      * Function called by the dependency manager when at least one dependency
40      * become unsatisfied or when the component is shutting down because for
41      * example bundle is being stopped.
42      *
43      */
44     void destroy() {
45         logger.debug("DESTROY called!");
46     }
47
48     /**
49      * Function called by dependency manager after "init ()" is called and after
50      * the services provided by the class are registered in the service registry
51      *
52      */
53     void start() {
54         logger.debug("START called!");
55     }
56
57     /**
58      * Function called by the dependency manager before the services exported by
59      * the component are unregistered, this will be followed by a "destroy ()"
60      * calls
61      *
62      */
63     void stop() {
64         logger.debug("STOP called!");
65     }
66
67     public void setPluginOutFlowProgrammerService(
68             IPluginOutFlowProgrammerService s) {
69         this.salNotifier = s;
70     }
71
72     public void unsetPluginOutFlowProgrammerService(
73             IPluginOutFlowProgrammerService s) {
74         if (this.salNotifier == s) {
75             this.salNotifier = null;
76         }
77     }
78
79     @Override
80     public void flowRemoved(Node node, Flow flow) {
81         if (!connectionOutService.isLocal(node)) {
82             logger.debug("flow removed will not be notified in a non-master controller for node "+node);
83             return;
84         }
85
86         if (salNotifier != null) {
87             salNotifier.flowRemoved(node, flow);
88         } else {
89             logger.warn("Unable to relay switch message to upper layer");
90         }
91     }
92
93     @Override
94     public void flowErrorReported(Node node, long rid, Object err) {
95         if (!connectionOutService.isLocal(node)) {
96             logger.debug("flow error will not be notified in a non-master controller for node "+node);
97             return;
98         }
99
100         if (salNotifier != null) {
101             salNotifier.flowErrorReported(node, rid, err);
102         } else {
103             logger.warn("Unable to relay switch error message to upper layer");
104         }
105     }
106
107     void setIPluginOutConnectionService(IPluginOutConnectionService s) {
108         connectionOutService = s;
109     }
110
111     void unsetIPluginOutConnectionService(IPluginOutConnectionService s) {
112         if (connectionOutService == s) {
113             connectionOutService = null;
114         }
115     }
116
117 }