blob: 4651c743d92c05810f8aa811cac93986d0ca539d [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
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
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
38 OFMessageFuture<List<OFStatistics>> {
39
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,
Ray Milkey269ffb92014-04-03 14:43:30 -070049 IOFSwitch sw, int transactionId, long timeout, TimeUnit unit) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080050 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 }
Ray Milkey269ffb92014-04-03 14:43:30 -070074
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080075 @Override
76 protected void unRegister() {
77 super.unRegister();
78 sw.cancelStatisticsReply(transactionId);
79 }
80}