[logback-dev] svn commit: r983 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Nov 22 13:07:51 CET 2006


Author: ceki
Date: Wed Nov 22 13:07:51 2006
New Revision: 983

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMonth.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByWeek.java
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/PeriodicStats.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByDay.java

Log:
ongoing work

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java	Wed Nov 22 13:07:51 2006
@@ -9,10 +9,10 @@
   double getDailyAverage();
  
   
-  long getWeeklyTotal();
-  long getWeeklyAverage();
+  long getLastWeeksCount();
+  double getWeeklyAverage();
   
-  long getMonthlyTotal();
-  long getMonthlyAverage();
+  long getLastMonthsCount();
+  double getMonthlyAverage();
   
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java	Wed Nov 22 13:07:51 2006
@@ -7,7 +7,9 @@
   final CountingFilter countingFilter;
   boolean started;
 
-  StatsByDay statsByDay = new StatsByDay(System.currentTimeMillis());
+  StatsByDay statsByDay = new StatsByDay();
+  StatsByWeek statsByWeek = new StatsByWeek();
+  StatsByMonth statsByMonth = new StatsByMonth();
   
   AccessStatsImpl(CountingFilter countingFilter) {
     this.countingFilter = countingFilter;
@@ -21,28 +23,32 @@
     return statsByDay.getLastCount();
   }
 
-  public long getMonthlyAverage() {
-    return 0;
+  public double getMonthlyAverage() {
+    return  statsByMonth.getAverage();
   }
 
-  public long getMonthlyTotal() {
-    return 0;
+  public long getLastMonthsCount() {
+    return statsByMonth.getLastCount();
   }
 
   public long getTotal() {
     return countingFilter.getTotal();
   }
 
-  public long getWeeklyAverage() {
-    return 0;
+  public double getWeeklyAverage() {
+    return statsByWeek.getAverage();
   }
 
-  public long getWeeklyTotal() {
-    return 0;
+  public long getLastWeeksCount() {
+    return statsByWeek.getLastCount();
   }
 
   void refresh(long now) {
-    statsByDay.refresh(now, getTotal());
+    long total = getTotal();
+    statsByDay.update(now, total);
+    statsByWeek.update(now, total);
+    statsByMonth.update(now, total);
+    
   }
 
   void refresh() {
@@ -52,7 +58,10 @@
 
   public void start() {
     started = true;
-
+    long now = System.currentTimeMillis();
+    statsByDay = new StatsByDay(now);
+    statsByWeek = new StatsByWeek(now);
+    statsByMonth = new StatsByMonth(now);
   }
 
   public boolean isStarted() {
@@ -61,6 +70,9 @@
 
   public void stop() {
     started = false;
+    statsByDay.reset();
+    statsByWeek.reset();
+    statsByMonth.reset();
   }
 
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/PeriodicStats.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/PeriodicStats.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/PeriodicStats.java	Wed Nov 22 13:07:51 2006
@@ -10,11 +10,15 @@
   private double average;
   private int n;
  
+  PeriodicStats() {
+    this(System.currentTimeMillis());
+  }
+  
   PeriodicStats(long now) {
     nextPeriodBegins = computeStartOfNextPeriod(now);
   }
  
-  void refresh(long now, long total) {
+  void update(long now, long total) {
     if (now > nextPeriodBegins) {     
       lastCount = total - lastTotal;
       lastTotal = total;
@@ -31,6 +35,18 @@
     return lastCount;
   }
   
+  void reset(long now) {
+    nextPeriodBegins = computeStartOfNextPeriod(now);
+    lastTotal = 0;
+    lastCount = 0;
+    average = 0.0;
+    n = 0;
+  }
+  
+  void reset() {
+    reset(System.currentTimeMillis());
+  }
+  
   abstract long computeStartOfNextPeriod(long now);
 
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByDay.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByDay.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByDay.java	Wed Nov 22 13:07:51 2006
@@ -3,13 +3,18 @@
 import ch.qos.logback.core.util.TimeUtil;
 
 public class StatsByDay extends PeriodicStats {
-  
+
+  StatsByDay() {
+    super();
+  }
+
   StatsByDay(long now) {
     super(now);
   }
+
   @Override
   long computeStartOfNextPeriod(long now) {
     return TimeUtil.computeStartOfNextDay(now);
   }
-  
+
 }

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMonth.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMonth.java	Wed Nov 22 13:07:51 2006
@@ -0,0 +1,20 @@
+package ch.qos.logback.access.filter;
+
+import ch.qos.logback.core.util.TimeUtil;
+
+public class StatsByMonth extends PeriodicStats {
+
+  StatsByMonth() {
+    super();
+  }
+  
+  StatsByMonth(long now) {
+    super(now);
+  }
+  
+  @Override
+  long computeStartOfNextPeriod(long now) {
+    return TimeUtil.computeStartOfNextMonth(now);
+  }
+  
+}

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByWeek.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByWeek.java	Wed Nov 22 13:07:51 2006
@@ -0,0 +1,19 @@
+package ch.qos.logback.access.filter;
+
+import ch.qos.logback.core.util.TimeUtil;
+
+public class StatsByWeek extends PeriodicStats {
+
+  StatsByWeek() {
+    super();
+  }
+  
+  StatsByWeek(long now) {
+    super(now);
+  }
+  @Override
+  long computeStartOfNextPeriod(long now) {
+    return TimeUtil.computeStartOfNextWeek(now);
+  }
+  
+}



More information about the logback-dev mailing list