KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > wstore > Counter


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.wstore;
15
16 import javax.servlet.*;
17 import javax.servlet.http.*;
18 import java.io.*;
19 import java.util.*;
20
21 import org.apache.log4j.Logger;
22 import org.compiere.util.*;
23 import org.compiere.www.*;
24
25 /**
26  * Web Page Counter
27  *
28  * @author Jorg Janke
29  * @version $Id: Counter.java,v 1.5 2003/07/28 03:59:07 jjanke Exp $
30  */

31 public class Counter extends HttpServlet implements Runnable JavaDoc
32 {
33     /** Logging */
34     private Logger log = Logger.getLogger(getClass());
35
36     /** Name */
37     static public final String JavaDoc NAME = "counter";
38
39     /** Requests */
40     private List m_requests = Collections.synchronizedList(new ArrayList());
41
42     /**
43      * Initialize global variables
44      *
45      * @param config servlet config
46      * @throws ServletException
47      */

48     public void init(ServletConfig config)
49         throws ServletException
50     {
51         super.init(config);
52         if (!WEnv.initWeb(config))
53             throw new ServletException("Counter.init");
54     } // init
55

56     /**
57      * Get Servlet information
58      * @return Info
59      */

60     public String JavaDoc getServletInfo()
61     {
62         return "Compiere Web Counter";
63     } // getServletInfo
64

65     /**
66      * Clean up resources
67      */

68     public void destroy()
69     {
70         log.info("destroy");
71     } // destroy
72

73     /*************************************************************************/
74
75     /**
76      * Process the HTTP Get request
77      *
78      * @param request request
79      * @param response response
80      * @throws ServletException
81      * @throws IOException
82      */

83     public void doGet (HttpServletRequest request, HttpServletResponse response)
84         throws ServletException, IOException
85     {
86         m_requests.add(request);
87         new Thread JavaDoc(this).start();
88     } // doGet
89

90     /**
91      * Process the HTTP Post request
92      *
93      * @param request request
94      * @param response response
95      * @throws ServletException
96      * @throws IOException
97      */

98     public void doPost (HttpServletRequest request, HttpServletResponse response)
99         throws ServletException, IOException
100     {
101         doGet (request, response);
102     } // doPost
103

104     /*************************************************************************/
105
106     /**
107      * Async Process
108      */

109     public void run()
110     {
111         long time = System.currentTimeMillis();
112         // get Request
113
HttpServletRequest request = null;
114         if (m_requests.size() > 0)
115             request = (HttpServletRequest)m_requests.remove(0);
116         if (request == null)
117         {
118             log.error("run - nothing in queue");
119             return;
120         }
121
122         Properties ctx = JSPEnv.getCtx(request);
123         String JavaDoc ref = request.getHeader("referer");
124         if (ref == null || ref.length() == 0)
125             ref = request.getRequestURL().toString();
126         log.info("Referer=" + request.getHeader("referer") + " - URL=" + request.getRequestURL());
127     } // run
128

129 } // Counter
130
Popular Tags