1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.access.filter;
15
16 import ch.qos.logback.core.spi.LifeCycle;
17
18 public class StatisticalViewImpl implements StatisticalView, LifeCycle {
19
20 final CountingFilter countingFilter;
21 boolean started;
22
23 StatsByMinute statsByMinute = new StatsByMinute();
24 StatsByHour statsByHour = new StatsByHour();
25 StatsByDay statsByDay = new StatsByDay();
26 StatsByWeek statsByWeek = new StatsByWeek();
27 StatsByMonth statsByMonth = new StatsByMonth();
28
29 StatisticalViewImpl(CountingFilter countingFilter) {
30 this.countingFilter = countingFilter;
31 }
32
33 public double getDailyAverage() {
34 return statsByDay.getAverage();
35 }
36
37 public long getLastDaysCount() {
38 return statsByDay.getLastCount();
39 }
40
41 public double getMonthlyAverage() {
42 return statsByMonth.getAverage();
43 }
44
45 public long getLastMonthsCount() {
46 return statsByMonth.getLastCount();
47 }
48
49 public long getTotal() {
50 return countingFilter.getTotal();
51 }
52
53 public double getWeeklyAverage() {
54 return statsByWeek.getAverage();
55 }
56
57 public long getLastWeeksCount() {
58 return statsByWeek.getLastCount();
59 }
60
61 void update(long now) {
62 long total = getTotal();
63 statsByMinute.update(now, total);
64 statsByHour.update(now, total);
65 statsByDay.update(now, total);
66 statsByWeek.update(now, total);
67 statsByMonth.update(now, total);
68
69 }
70
71 void update() {
72 long now = System.currentTimeMillis();
73 update(now);
74 }
75
76 public void start() {
77 System.out.println("StatisticalViewImpl start called");
78 started = true;
79 long now = System.currentTimeMillis();
80 statsByMinute = new StatsByMinute(now);
81 statsByHour = new StatsByHour(now);
82 statsByDay = new StatsByDay(now);
83 statsByWeek = new StatsByWeek(now);
84 statsByMonth = new StatsByMonth(now);
85 }
86
87 public boolean isStarted() {
88 return started;
89 }
90
91 public void stop() {
92 started = false;
93 statsByMinute.reset();
94 statsByHour.reset();
95 statsByDay.reset();
96 statsByWeek.reset();
97 statsByMonth.reset();
98 }
99
100 public long getLastMinuteCount() {
101 return statsByMinute.getLastCount();
102 }
103
104 public double getMinuteAverage() {
105 return statsByMinute.getAverage();
106 }
107
108 public double getHourlyAverage() {
109 return statsByHour.getAverage();
110 }
111
112 public long getLastHoursCount() {
113 return statsByHour.getLastCount();
114 }
115
116 }