3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import java.util.concurrent.CopyOnWriteArrayList;
15 import java.util.concurrent.CountDownLatch;
17 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
18 import org.openflow.protocol.OFError;
19 import org.openflow.protocol.OFStatisticsReply;
20 import org.openflow.protocol.OFStatisticsRequest;
21 import org.openflow.protocol.statistics.OFStatistics;
23 public class StatisticsCollector implements Callable<Object> {
27 private OFStatisticsRequest request;
28 private CountDownLatch latch;
29 private Object result;
30 private List<OFStatistics> stats;
32 public StatisticsCollector(ISwitch sw, int xid, OFStatisticsRequest request) {
35 this.request = request;
36 latch = new CountDownLatch(1);
37 result = new Object();
38 stats = new CopyOnWriteArrayList<OFStatistics>();
42 * accumulate the stats records in result
43 * Returns: true: if this is the last record
46 public boolean collect(OFStatisticsReply reply) {
47 synchronized (result) {
48 stats.addAll(reply.getStatistics());
49 if ((reply.getFlags() & 0x01) == 0) {
50 // all stats are collected, done
54 // still waiting for more to come
61 public Object call() throws Exception {
62 sw.asyncSend(request, xid);
63 // free up the request as it is no longer needed
65 // wait until all stats replies are received or timeout
70 public Integer getXid() {
74 public void wakeup() {
75 this.latch.countDown();
78 public void wakeup(OFError errorMsg) {