blob: 91b81c1b3abc0dcc3928e2c26e368445d7ff7044 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
18package net.floodlightcontroller.core.internal;
19
20import java.util.List;
21import java.util.concurrent.CopyOnWriteArrayList;
22import java.util.concurrent.TimeUnit;
23
24import net.floodlightcontroller.core.IOFSwitch;
25import net.floodlightcontroller.threadpool.IThreadPoolService;
26
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070027import org.projectfloodlight.openflow.protocol.OFMessage;
28import org.projectfloodlight.openflow.protocol.OFStatsReply;
29import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
30import org.projectfloodlight.openflow.protocol.OFType;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031
32/**
33 * A concrete implementation that handles asynchronously receiving OFStatistics
Ray Milkey269ffb92014-04-03 14:43:30 -070034 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080035 * @author David Erickson (daviderickson@cs.stanford.edu)
36 */
37public class OFStatisticsFuture extends
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070038 OFMessageFuture<List<OFStatsReply>> {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080039
40 protected volatile boolean finished;
41
42 public OFStatisticsFuture(IThreadPoolService tp,
Ray Milkey269ffb92014-04-03 14:43:30 -070043 IOFSwitch sw, int transactionId) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080044 super(tp, sw, OFType.STATS_REPLY, transactionId);
45 init();
46 }
47
48 public OFStatisticsFuture(IThreadPoolService tp,
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070049 IOFSwitch sw, int transactionId, long timeout,
50 TimeUnit unit) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080051 super(tp, sw, OFType.STATS_REPLY, transactionId, timeout, unit);
52 init();
53 }
54
55 private void init() {
56 this.finished = false;
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070057 this.result = new CopyOnWriteArrayList<OFStatsReply>();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 }
59
60 @Override
61 protected void handleReply(IOFSwitch sw, OFMessage msg) {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070062 OFStatsReply sr = (OFStatsReply) msg;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 synchronized (this.result) {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070064 this.result.add(sr);
65 if ( !(sr.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) ) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080066 this.finished = true;
67 }
68 }
69 }
70
71 @Override
72 protected boolean isFinished() {
73 return finished;
74 }
Ray Milkey269ffb92014-04-03 14:43:30 -070075
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080076 @Override
77 protected void unRegister() {
78 super.unRegister();
79 sw.cancelStatisticsReply(transactionId);
80 }
81}