Source Code Cross Referenced for PerformanceFilter.java in  » J2EE » Dinamica » dinamica » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Dinamica » dinamica 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dinamica;
002:
003:        import java.io.*;
004:        import javax.servlet.*;
005:        import javax.servlet.http.*;
006:
007:        /**
008:         * 
009:         * Servlet filter to generate a performance log
010:         * according to the configured filter map and 
011:         * the init parameter "limit". A value of 0 will
012:         * log all requests, a value > 0 will log only those request
013:         * whose execution takes more than "limit" milliseconds.
014:         * 
015:         * <br>
016:         * Creation date: 5/jan/2004<br>
017:         * Last Update: 5/jan/2004<br>
018:         * (c) 2003 Martin Cordova<br>
019:         * This code is released under the LGPL license<br>
020:         * @author Martin Cordova
021:         *
022:         */
023:
024:        public class PerformanceFilter implements  Filter {
025:
026:            //filter configuration object
027:            private FilterConfig _config = null;
028:
029:            //log threshold (log requests that take more than N milliseconds)
030:            private int _limit = 0;
031:
032:            /**
033:             * init filter
034:             **/
035:            public void init(FilterConfig config) throws ServletException {
036:
037:                _config = config;
038:
039:                //load "limit" config parameter
040:                String l = _config.getInitParameter("limit");
041:                if (l != null)
042:                    _limit = Integer.parseInt(l);
043:
044:            }
045:
046:            /**
047:             * clean up
048:             **/
049:            public void destroy() {
050:                _config = null;
051:            }
052:
053:            /**
054:             * Filter main method
055:             */
056:            public void doFilter(ServletRequest request,
057:                    ServletResponse response, FilterChain next)
058:
059:            throws IOException, ServletException
060:
061:            {
062:
063:                long t1 = 0;
064:                long t2 = 0;
065:
066:                t1 = System.currentTimeMillis();
067:
068:                HttpServletRequest req = (HttpServletRequest) request;
069:
070:                //measure performance
071:                try {
072:
073:                    t1 = System.currentTimeMillis();
074:                    next.doFilter(request, response);
075:                    t2 = System.currentTimeMillis();
076:                    long tt = t2 - t1;
077:
078:                    //save log if necessary
079:                    if (tt > _limit) {
080:                        saveLog(req, tt);
081:                    }
082:
083:                }
084:
085:                catch (Throwable e) {
086:                    throw new ServletException(e);
087:                }
088:
089:            }
090:
091:            /**
092:             * Save performance record to output device (file, database table, etc.)
093:             * @param req HTTP Servlet Request to extract useful information
094:             * @param t Elapsed time in milliseconds
095:             * @throws Throwable
096:             */
097:            void saveLog(HttpServletRequest req, long t) throws Throwable {
098:                String d = StringUtil.formatDate(new java.util.Date(),
099:                        "yyyy-MM-dd HH:mm:ss");
100:                String uri = req.getRequestURI();
101:                String tt = String.valueOf(t);
102:                String ip = req.getRemoteAddr();
103:                String method = req.getMethod();
104:
105:                String msg = d + "\t" + uri + "\t" + method + "\t" + ip + "\t"
106:                        + tt;
107:
108:                String file = _config.getInitParameter("path");
109:
110:                StringUtil.saveMessage(file, msg);
111:            }
112:
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.