KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > admin > StatisticsLogger


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool.admin;
7
8 import org.apache.commons.logging.Log;
9 import org.logicalcobwebs.proxool.ProxoolConstants;
10
11 import java.text.DateFormat JavaDoc;
12 import java.text.DecimalFormat JavaDoc;
13 import java.text.SimpleDateFormat JavaDoc;
14
15 /**
16  * Listens to statistics and logs them
17  * @version $Revision: 1.3 $, $Date: 2006/01/18 14:39:57 $
18  * @author bill
19  * @author $Author: billhorsman $ (current maintainer)
20  * @since Proxool 0.7
21  */

22 public class StatisticsLogger implements StatisticsListenerIF {
23
24     private static final DecimalFormat JavaDoc DECIMAL_FORMAT = new DecimalFormat JavaDoc("0.00");
25
26     private static final DateFormat JavaDoc TIME_FORMAT = new SimpleDateFormat JavaDoc("HH:mm:ss");
27
28     private Log log;
29
30     private String JavaDoc logLevel;
31
32     public StatisticsLogger(Log log, String JavaDoc logLevel) {
33         this.log = log;
34         this.logLevel = logLevel;
35     }
36
37     public void statistics(String JavaDoc alias, StatisticsIF statistics) {
38
39         if (statistics != null && logLevel != null) {
40
41                 StringBuffer JavaDoc out = new StringBuffer JavaDoc();
42
43                 out.append(TIME_FORMAT.format(statistics.getStartDate()));
44                 out.append(" - ");
45                 out.append(TIME_FORMAT.format(statistics.getStopDate()));
46                 out.append(", s:");
47                 out.append(statistics.getServedCount());
48                 out.append(":");
49                 out.append(DECIMAL_FORMAT.format(statistics.getServedPerSecond()));
50
51                 out.append("/s, r:");
52                 out.append(statistics.getRefusedCount());
53                 out.append(":");
54                 out.append(DECIMAL_FORMAT.format(statistics.getRefusedPerSecond()));
55
56                 out.append("/s, a:");
57                 out.append(DECIMAL_FORMAT.format(statistics.getAverageActiveTime()));
58                 out.append("ms/");
59                 out.append(DECIMAL_FORMAT.format(statistics.getAverageActiveCount()));
60
61                 if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_TRACE)) {
62                     log.trace(out.toString());
63                 } else if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG)) {
64                     log.debug(out.toString());
65                 } else if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_INFO)) {
66                     log.info(out.toString());
67                 }
68
69             }
70
71     }
72 }
73
74
75 /*
76  Revision history:
77  $Log: StatisticsLogger.java,v $
78  Revision 1.3 2006/01/18 14:39:57 billhorsman
79  Unbundled Jakarta's Commons Logging.
80
81  Revision 1.2 2003/03/03 11:11:59 billhorsman
82  fixed licence
83
84  Revision 1.1 2003/02/19 23:36:51 billhorsman
85  renamed monitor package to admin
86
87  Revision 1.1 2003/02/07 14:16:46 billhorsman
88  support for StatisticsListenerIF
89
90  */
Popular Tags