alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.statistic; |
| 2 | |
| 3 | import org.onlab.onos.net.flow.FlowRuleProvider; |
| 4 | |
| 5 | /** |
| 6 | * Implementation of a load. |
| 7 | */ |
| 8 | public class DefaultLoad implements Load { |
| 9 | |
| 10 | private final boolean isValid; |
| 11 | private final long current; |
| 12 | private final long previous; |
| 13 | private final long time; |
| 14 | |
| 15 | /** |
| 16 | * Creates an invalid load. |
| 17 | */ |
| 18 | public DefaultLoad() { |
| 19 | this.isValid = false; |
| 20 | this.time = System.currentTimeMillis(); |
| 21 | this.current = -1; |
| 22 | this.previous = -1; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Creates a load value from the parameters. |
| 27 | * @param current the current value |
| 28 | * @param previous the previous value |
| 29 | */ |
| 30 | public DefaultLoad(long current, long previous) { |
| 31 | this.current = current; |
| 32 | this.previous = previous; |
| 33 | this.time = System.currentTimeMillis(); |
| 34 | this.isValid = true; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public long rate() { |
| 39 | return (current - previous) / FlowRuleProvider.POLL_INTERVAL; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public long latest() { |
| 44 | return current; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean isValid() { |
| 49 | return isValid; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public long time() { |
| 54 | return time; |
| 55 | } |
| 56 | } |