blob: f0f890a02aef33b0ea6fd2ef5c80a7f2fd1616e6 [file] [log] [blame]
alshabib3d643ec2014-10-22 18:33:00 -07001package org.onlab.onos.net.statistic;
2
alshabib23a8d7c2014-10-22 21:53:39 -07003import com.google.common.base.MoreObjects;
alshabib3d643ec2014-10-22 18:33:00 -07004import org.onlab.onos.net.flow.FlowRuleProvider;
5
6/**
7 * Implementation of a load.
8 */
9public class DefaultLoad implements Load {
10
11 private final boolean isValid;
12 private final long current;
13 private final long previous;
14 private final long time;
15
16 /**
17 * Creates an invalid load.
18 */
19 public DefaultLoad() {
20 this.isValid = false;
21 this.time = System.currentTimeMillis();
22 this.current = -1;
23 this.previous = -1;
24 }
25
26 /**
27 * Creates a load value from the parameters.
28 * @param current the current value
29 * @param previous the previous value
30 */
31 public DefaultLoad(long current, long previous) {
32 this.current = current;
33 this.previous = previous;
34 this.time = System.currentTimeMillis();
35 this.isValid = true;
36 }
37
38 @Override
39 public long rate() {
40 return (current - previous) / FlowRuleProvider.POLL_INTERVAL;
41 }
42
43 @Override
44 public long latest() {
45 return current;
46 }
47
48 @Override
49 public boolean isValid() {
50 return isValid;
51 }
52
53 @Override
54 public long time() {
55 return time;
56 }
alshabib23a8d7c2014-10-22 21:53:39 -070057
58 @Override
59 public String toString() {
60 return MoreObjects.toStringHelper("Load").add("rate", rate())
61 .add("latest", latest()).toString();
62
63 }
alshabib3d643ec2014-10-22 18:33:00 -070064}