Bug 6110: Fixed bugs in statistics manager due to race condition.
[openflowplugin.git] / applications / statistics-manager / src / main / java / org / opendaylight / openflowplugin / applications / statistics / manager / StatRpcMsgManager.java
1 /**
2  * Copyright (c) 2014 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.applications.statistics.manager;
10
11 import java.util.List;
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionAware;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21
22 import com.google.common.base.Optional;
23 import com.google.common.util.concurrent.SettableFuture;
24
25 /**
26  * statistics-manager
27  * org.opendaylight.openflowplugin.applications.statistics.manager
28  *
29  * StatRpcMsgManager
30  * It represent access point for Device statistics RPC services which are
31  * filtered for needed methods only and they are wrapped in simply way.
32  * Many statistics responses are Multipart messages, so StatRpcMsgManager
33  * provide a functionality to add all multipart msg and provides back whole
34  * stack to listener when listener catch the last Multipart msg.
35  *
36  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
37  *
38  * Created: Aug 29, 2014
39  */
40 public interface StatRpcMsgManager {
41     /**
42      * Transaction container is definition for Multipart transaction
43      * join container for all Multipart msg with same TransactionId
44      * Input {@link DataObject} is a possible light-weight DataObject
45      * which is used for identification (e.g. Flow -&gt; Priority,Match,Cookie,FlowId)
46      *
47      * @param <T>
48      */
49     interface TransactionCacheContainer<T extends TransactionAware> {
50
51         void addNotif(T notification);
52
53         TransactionId getId();
54
55         NodeId getNodeId();
56
57         Optional<? extends DataObject> getConfInput();
58
59         List<T> getNotifications();
60     }
61
62     /**
63      * Method is used for check a transaction registration
64      * for multipart cache holder
65      *
66      * @param id
67      * @return true if the transaction has been correctly registered
68      */
69     Future<Boolean> isExpectedStatistics(TransactionId id, NodeId nodeId);
70
71     /**
72      * Method converts {@link java.util.concurrent.Future} object to listenenable future which
73      * is registered for Multipart Notification Statistics Collecting processing.
74      *
75      * @param future - result every Device RPC call
76      */
77     <T extends TransactionAware, D extends DataObject> void registrationRpcFutureCallBack(
78             Future<RpcResult<T>> future, D inputObj, NodeRef ref, SettableFuture<TransactionId> resultTransId);
79
80     /**
81      * Method adds Notification which is marked as Multipart to the transaction cash
82      * to wait for the last one.
83      *
84      * @param notification
85      */
86     <T extends TransactionAware> void addNotification(T notification, NodeId nodeId);
87
88     /**
89      * The last Multipart should inform code about possibility to take all previous
90      * messages for next processing. The method take all msg and possible input object
91      * and build all to TransactionCacheContainer Object to return. This process clean
92      * all instances in Cache.
93      *
94      * @param id
95      * @return TransactionCacheContainer
96      */
97     Future<Optional<TransactionCacheContainer<?>>> getTransactionCacheContainer(TransactionId id, NodeId nodeId);
98
99     /**
100      * Method wraps OpendaylightGroupStatisticsService.getAllGroupStatistics
101      * and registers to Transaction Cache
102      *
103      * @param nodeRef
104      */
105     Future<TransactionId> getAllGroupsStat(NodeRef nodeRef);
106
107     /**
108      * Method wraps OpendaylightGroupStatisticsService.getGroupDescription
109      * and registers to Transaction Cache
110      *
111      * @param nodeRef
112      */
113     Future<TransactionId> getAllGroupsConfStats(NodeRef nodeRef);
114
115     /**
116      * Method wraps OpendaylightMeterStatisticsService.getGroupFeatures
117      * and registers to Transaction Cache
118      *
119      * @param nodeRef
120      */
121     void getGroupFeaturesStat(NodeRef nodeRef);
122
123     /**
124      * Method wraps OpendaylightMeterStatisticsService.getAllMeterStatistics
125      * and registers to Transaction Cache
126      *
127      * @param nodeRef
128      */
129     Future<TransactionId> getAllMetersStat(NodeRef nodeRef);
130
131     /**
132      * Method wraps OpendaylightMeterStatisticsService.getAllMeterConfigStatistics
133      * and registers to Transaction Cache
134      *
135      * @param nodeRef
136      */
137     Future<TransactionId> getAllMeterConfigStat(NodeRef nodeRef);
138
139     /**
140      * Method wraps OpendaylightMeterStatisticsService.getMeterFeatures
141      * and registers to Transaction Cache
142      *
143      * @param nodeRef
144      */
145     void getMeterFeaturesStat(NodeRef nodeRef);
146
147     /**
148      * Method wraps OpendaylightFlowStatisticsService.getAllFlowsStatisticsFromAllFlowTables
149      * and registers to Transaction Cache
150      *
151      * @param nodeRef
152      */
153     Future<TransactionId> getAllFlowsStat(NodeRef nodeRef);
154
155     /**
156      * Method wraps OpendaylightFlowStatisticsService.getAggregateFlowStatisticsFromFlowTableForAllFlows
157      * and registers to Transaction Cache
158      *
159      * @param nodeRef
160      * @param tableId
161      */
162     void getAggregateFlowStat(NodeRef nodeRef, TableId tableId);
163
164     /**
165      * Method wraps OpendaylightPortStatisticsService.getAllNodeConnectorsStatistics
166      * and registers to Transaction Cache
167      *
168      * @param nodeRef
169      */
170     Future<TransactionId> getAllPortsStat(NodeRef nodeRef);
171
172     /**
173      * Method wraps OpendaylightFlowTableStatisticsService.getFlowTablesStatistics
174      * and registers to Transaction Cache
175      *
176      * @param nodeRef
177      */
178     Future<TransactionId> getAllTablesStat(NodeRef nodeRef);
179
180     /**
181      * Method wraps OpendaylightQueueStatisticsService.getAllQueuesStatisticsFromAllPorts
182      * and registers to Transaction Cache
183      *
184      * @param nodeRef
185      */
186     Future<TransactionId> getAllQueueStat(NodeRef nodeRef);
187
188 }
189