blob: e8a547a516bab83395aa9b73affd425e85b897bd [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.counter;
19
20import java.util.Arrays;
21import java.util.Date;
22
23import net.floodlightcontroller.counter.ICounter.DateSpan;
24
25/**
26 * Simple immutable class to store a series of historic counter values
27 *
28 * This could probably use a re-think...
29 *
30 * @author kyle
31 *
32 */
33public class CountSeries {
34 protected long[] counterValues;
35 protected Date startDate;
36 protected DateSpan dateSpan;
37
38 public CountSeries(Date startDate, DateSpan dateSpan, long[] counterValues) {
39 this.counterValues = counterValues.clone();
40 this.dateSpan = dateSpan;
41 this.startDate = startDate;
42 }
43
44
45 public long[] getSeries() { //synchronized here should lock on 'this', implying that it shares the lock with increment
46 return this.counterValues.clone();
47 }
48
49 /**
50 * Returns the startDate of this series. The first long in getSeries represents the sum of deltas from increment calls with dates
51 * that correspond to >= startDate and < startDate + DateSpan.
52 * @return
53 */
54 public Date getStartDate() {//synchronized here should lock on 'this', implying that it shares the lock with increment
55 return this.startDate;
56 }
57
58 public String toString() {
59 String ret = "{start: " + this.startDate + ", span: " + this.dateSpan + ", series: " + Arrays.toString(getSeries()) + "}";
60 return ret;
61 }
62
63 /**
64 * Return a long that is the number of milliseconds in a ds (second/minute/hour/day/week). (Utility method.)
65 *
66 * @param ds
67 * @return
68 */
69 public static final long dateSpanToMilliseconds(DateSpan ds) {
70 long delta = 1;
71 switch(ds) {
72 case WEEKS:
73 delta *= 7;
74 case DAYS:
75 delta *= 24;
76 case HOURS:
77 delta *= 60;
78 case MINUTES:
79 delta *= 60;
80 case SECONDS:
81 delta *= 1000;
82 default:
83 break;
84 }
85 return delta;
86 }
87
88}