KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > services > StatisticsService


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.deliver.services;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.infoglue.cms.util.CmsPropertyHandler;
30 import org.infoglue.deliver.util.webloggers.CommonLogger;
31 import org.infoglue.deliver.util.webloggers.Logger;
32 import org.infoglue.deliver.util.webloggers.W3CExtendedLogger;
33
34
35 /**
36  * This class is thought of as an service which logs statistics about a request so that log analyzers later on can
37  * extract information from it. The thought is to have all delivery-engines report to a central service
38  * about their requests so the logfiles get merged at once. The service should be very performance centered and
39  * only write to the logfile when the system is low on use.
40  *
41  * Frank (03/04/2005): Only logs statistics if statistics.enabled=true in the deliver configuration file.
42  */

43 public class StatisticsService
44 {
45     private static StatisticsService statisticsService = null;
46     private Logger logger;
47
48     /**
49      * A private constructor
50      * Could later on be specialized to use other loggers as well.
51      */

52
53     private StatisticsService()
54     {
55         this.logger = new CommonLogger();
56
57         String JavaDoc statisticsLogger = CmsPropertyHandler.getStatisticsLogger();
58         if(statisticsLogger != null && statisticsLogger.equalsIgnoreCase("W3CExtendedLogger"))
59             this.logger = new W3CExtendedLogger();
60     }
61
62     /**
63      * A factory singleton implementation
64      */

65
66     public static StatisticsService getStatisticsService()
67     {
68         if(statisticsService == null)
69             statisticsService = new StatisticsService();
70
71         return statisticsService;
72     }
73
74     /**
75      * This method registers a request to the distributed service.
76      * For now it only logs the request - bad boy!!!!
77      *
78      * It only logs the request if statistics were enabled in the configuration file.
79      */

80     public void registerRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, String JavaDoc pagePath, long elapsedTime)
81     {
82         String JavaDoc enabled = CmsPropertyHandler.getStatisticsEnabled();
83         if(Boolean.valueOf(enabled).booleanValue())
84             this.logger.logRequest(request, response, pagePath, elapsedTime);
85     }
86 }
Popular Tags