blob: 4d3f733a6ed1d3e6b7dbba272643680877f9e982 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* 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**/
17
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
27import org.openflow.protocol.OFMessage;
28import org.openflow.protocol.OFStatisticsReply;
29import org.openflow.protocol.OFType;
30import org.openflow.protocol.statistics.OFStatistics;
31
32/**
33 * A concrete implementation that handles asynchronously receiving OFStatistics
34 *
35 * @author David Erickson (daviderickson@cs.stanford.edu)
36 */
37public class OFStatisticsFuture extends
38 OFMessageFuture<List<OFStatistics>> {
39
40 protected volatile boolean finished;
41
42 public OFStatisticsFuture(IThreadPoolService tp,
43 IOFSwitch sw, int transactionId) {
44 super(tp, sw, OFType.STATS_REPLY, transactionId);
45 init();
46 }
47
48 public OFStatisticsFuture(IThreadPoolService tp,
49 IOFSwitch sw, int transactionId, long timeout, TimeUnit unit) {
50 super(tp, sw, OFType.STATS_REPLY, transactionId, timeout, unit);
51 init();
52 }
53
54 private void init() {
55 this.finished = false;
56 this.result = new CopyOnWriteArrayList<OFStatistics>();
57 }
58
59 @Override
60 protected void handleReply(IOFSwitch sw, OFMessage msg) {
61 OFStatisticsReply sr = (OFStatisticsReply) msg;
62 synchronized (this.result) {
63 this.result.addAll(sr.getStatistics());
64 if ((sr.getFlags() & 0x1) == 0) {
65 this.finished = true;
66 }
67 }
68 }
69
70 @Override
71 protected boolean isFinished() {
72 return finished;
73 }
74
75 @Override
76 protected void unRegister() {
77 super.unRegister();
78 sw.cancelStatisticsReply(transactionId);
79 }
80}