View Javadoc

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