Source Code Cross Referenced for TextFormatProvider.java in  » Profiler » MessAdmin » clime » messadmin » providers » displayformat » 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 » Profiler » MessAdmin » clime.messadmin.providers.displayformat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package clime.messadmin.providers.displayformat;
004:
005:        import java.io.IOException;
006:        import java.io.PrintWriter;
007:        import java.text.DateFormat;
008:        import java.text.NumberFormat;
009:        import java.text.SimpleDateFormat;
010:        import java.util.Collection;
011:        import java.util.Date;
012:        import java.util.Iterator;
013:        import java.util.Map;
014:        import java.util.Set;
015:
016:        import javax.servlet.ServletConfig;
017:        import javax.servlet.ServletContext;
018:        import javax.servlet.ServletException;
019:        import javax.servlet.http.HttpServletRequest;
020:        import javax.servlet.http.HttpServletResponse;
021:
022:        import clime.messadmin.i18n.I18NSupport;
023:        import clime.messadmin.model.IApplicationInfo;
024:        import clime.messadmin.model.IServerInfo;
025:        import clime.messadmin.model.ISessionInfo;
026:        import clime.messadmin.providers.spi.DisplayFormatProvider;
027:        import clime.messadmin.providers.spi.SerializableProvider;
028:        import clime.messadmin.providers.spi.SizeOfProvider;
029:        import clime.messadmin.utils.BytesFormat;
030:
031:        /**
032:         * @author Cédrik LIME
033:         * @since 4.1
034:         */
035:        public class TextFormatProvider implements  DisplayFormatProvider {
036:            /**
037:             * Modified ISO 8601 datetime format: {@value}
038:             * @see <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601 / European Standard EN 28601  DateTime</a>
039:             * @see <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3399</a>
040:             */
041:            protected static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";//$NON-NLS-1$
042:            private transient ServletConfig config;
043:
044:            /**
045:             * 
046:             */
047:            public TextFormatProvider() {
048:                super ();
049:            }
050:
051:            /* (non-Javadoc)
052:             * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
053:             */
054:            public int getPriority() {
055:                return 0;
056:            }
057:
058:            /* (non-Javadoc)
059:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#getFormatID()
060:             */
061:            public String getFormatID() {
062:                return "text";//$NON-NLS-1$
063:            }
064:
065:            /* (non-Javadoc)
066:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#getContentType()
067:             */
068:            public String getContentType() {
069:                return "text/plain;charset=UTF-8";//$NON-NLS-1$
070:            }
071:
072:            /* (non-Javadoc)
073:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#init(javax.servlet.ServletConfig)
074:             */
075:            public void init(ServletConfig config) throws ServletException {
076:                this .config = config;
077:            }
078:
079:            /**
080:             * Returns this servlet's {@link ServletConfig} object.
081:             *
082:             * @return ServletConfig 	the <code>ServletConfig</code> object
083:             *				that initialized this servlet
084:             */
085:            public ServletConfig getServletConfig() {
086:                return config;
087:            }
088:
089:            /**
090:             * Returns a reference to the {@link ServletContext} in which this servlet
091:             * is running.  See {@link ServletConfig#getServletContext}.
092:             *
093:             * <p>This method is supplied for convenience. It gets the 
094:             * context from the servlet's <code>ServletConfig</code> object.
095:             *
096:             * @return ServletContext 	the <code>ServletContext</code> object
097:             *				passed to this servlet by the <code>init</code>
098:             *				method
099:             */
100:            public ServletContext getServletContext() {
101:                ServletConfig sc = getServletConfig();
102:                if (sc == null) {
103:                    throw new IllegalStateException(
104:                            "err.servlet_config_not_initialized");
105:                }
106:                return sc.getServletContext();
107:            }
108:
109:            /* (non-Javadoc)
110:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#preProcess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
111:             */
112:            public void preProcess(HttpServletRequest req,
113:                    HttpServletResponse resp) throws ServletException,
114:                    IOException {
115:                // nothing
116:            }
117:
118:            /* (non-Javadoc)
119:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayWebAppsList(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
120:             */
121:            public void displayWebAppsList(HttpServletRequest req,
122:                    HttpServletResponse resp,
123:                    Set/*<IApplicationInfo>*/applicationInfos)
124:                    throws ServletException, IOException {
125:                NumberFormat numberFormat = NumberFormat
126:                        .getNumberInstance(I18NSupport.getAdminLocale());
127:                PrintWriter out = resp.getWriter();
128:                writeMenu(req, resp, out);
129:                out.println();
130:                out.println("List of available applications:");
131:                out.println();
132:                Iterator iter = applicationInfos.iterator();
133:                while (iter.hasNext()) {
134:                    IApplicationInfo app = (IApplicationInfo) iter.next();
135:                    writeMenu(req, resp, out, app);
136:                    out.println("Id:\t\t\t" + app.getInternalContextPath());
137:                    out.println("Context:\t\t" + app.getContextPath());
138:                    out.println("Name:\t\t\t" + app.getServletContextName());
139:                    out
140:                            .println("# active sessions:\t"
141:                                    + numberFormat.format(app
142:                                            .getActiveSessionsCount()));
143:                    out.println();
144:                }
145:                out.close();
146:            }
147:
148:            /* (non-Javadoc)
149:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#displaySessionsListPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
150:             */
151:            public void displaySessionsListPage(HttpServletRequest req,
152:                    HttpServletResponse resp, String sortBy, String orderBy,
153:                    IApplicationInfo webAppStats,
154:                    Collection/*<ISessionInfo>*/activeSessions,
155:                    Collection/*<String>*/passiveSessionsIds)
156:                    throws ServletException, IOException {
157:                BytesFormat bytesFormat = new BytesFormat(I18NSupport
158:                        .getAdminLocale(), " ");//$NON-NLS-1$
159:                NumberFormat numberFormat = NumberFormat
160:                        .getNumberInstance(I18NSupport.getAdminLocale());
161:                DateFormat dateTimeFormat = DateFormat.getDateInstance(
162:                        DateFormat.DEFAULT, I18NSupport.getAdminLocale());
163:                ((SimpleDateFormat) dateTimeFormat)
164:                        .applyPattern(DATE_TIME_PATTERN);
165:                PrintWriter out = resp.getWriter();
166:                writeMenu(req, resp, out);
167:                writeMenu(req, resp, out, webAppStats);
168:                out.println();
169:                out.println("" + numberFormat.format(activeSessions.size())
170:                        + " active sessions for "
171:                        + webAppStats.getContextPath());
172:                out.println("("
173:                        + numberFormat.format(passiveSessionsIds.size())
174:                        + " passivated sessions)");
175:                out.println();
176:                Iterator iter = activeSessions.iterator();
177:                while (iter.hasNext()) {
178:                    ISessionInfo session = (ISessionInfo) iter.next();
179:                    writeMenu(req, resp, out, webAppStats, session);
180:                    out.println("Id:\t\t\t" + session.getId());
181:                    out.println("Locale:\t\t\t" + session.getGuessedLocale());
182:                    out.println("User:\t\t\t" + session.getGuessedUser());
183:                    out.println("Creation date:\t\t"
184:                            + dateTimeFormat.format(new Date(session
185:                                    .getCreationTime())));
186:                    out.println("Last access time:\t"
187:                            + dateTimeFormat.format(new Date(session
188:                                    .getLastAccessedTime())));
189:                    out.println("Idle time:\t\t" + session.getIdleTime());
190:                    out.println("TTL:\t\t\t" + session.getTTL());
191:                    out.println("Size:\t\t\t"
192:                            + bytesFormat.format(session.getSize()));
193:                    out.println();
194:                }
195:                out.close();
196:            }
197:
198:            /* (non-Javadoc)
199:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#displaySessionDetailPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String)
200:             */
201:            public void displaySessionDetailPage(HttpServletRequest req,
202:                    HttpServletResponse resp, IApplicationInfo webAppStats,
203:                    ISessionInfo currentSession) throws ServletException,
204:                    IOException {
205:                BytesFormat bytesFormat = new BytesFormat(I18NSupport
206:                        .getAdminLocale(), " ");//$NON-NLS-1$
207:                NumberFormat numberFormat = NumberFormat
208:                        .getNumberInstance(I18NSupport.getAdminLocale());
209:                PrintWriter out = resp.getWriter();
210:                writeMenu(req, resp, out);
211:                writeMenu(req, resp, out, webAppStats);
212:                out.println();
213:                out.println("Id:\t\t" + currentSession.getId());
214:                out.println("Remote host:\t" + currentSession.getRemoteHost());
215:                out.println("User:\t\t" + currentSession.getGuessedUser());
216:                out.println("Locale:\t\t" + currentSession.getGuessedLocale());
217:                out.println("# hits:\t\t"
218:                        + numberFormat.format(currentSession.getHits()));
219:                out.println("Size:\t\t"
220:                        + bytesFormat.format(currentSession.getSize()));
221:                out.println();
222:                // Session attributes
223:                Map attributes = currentSession.getAttributes();
224:                out.println("# attributes:\t"
225:                        + numberFormat.format(attributes.size()));
226:                Iterator iter = attributes.entrySet().iterator();
227:                while (iter.hasNext()) {
228:                    Map.Entry entry = (Map.Entry) iter.next();
229:                    out.println("\tAttribute name:\t" + entry.getKey());
230:                    out.println("\tAttribute Class:\t"
231:                            + (entry.getValue() != null ? entry.getValue()
232:                                    .getClass().getName() : ""));
233:                    out.println("\tAttribute size:\t"
234:                            + bytesFormat.format(SizeOfProvider.Util
235:                                    .getObjectSize(entry.getValue(),
236:                                            webAppStats.getClassLoader())));
237:                    if (!SerializableProvider.Util.isSerializable(entry
238:                            .getValue(), webAppStats.getClassLoader())) {
239:                        out.println("\tAttribute is not Serializable!");
240:                    }
241:                    out.println();
242:                }
243:                out.close();
244:            }
245:
246:            /* (non-Javadoc)
247:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayWebAppStatsPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
248:             */
249:            public void displayWebAppStatsPage(HttpServletRequest req,
250:                    HttpServletResponse resp, IApplicationInfo webAppStats)
251:                    throws ServletException, IOException {
252:                BytesFormat bytesFormat = new BytesFormat(I18NSupport
253:                        .getAdminLocale(), " ");//$NON-NLS-1$
254:                NumberFormat numberFormat = NumberFormat
255:                        .getNumberInstance(I18NSupport.getAdminLocale());
256:                DateFormat dateTimeFormat = DateFormat.getDateInstance(
257:                        DateFormat.DEFAULT, I18NSupport.getAdminLocale());
258:                ((SimpleDateFormat) dateTimeFormat)
259:                        .applyPattern(DATE_TIME_PATTERN);
260:                PrintWriter out = resp.getWriter();
261:                writeMenu(req, resp, out);
262:                writeMenu(req, resp, out, webAppStats);
263:                out.println();
264:                out.println("Details for " + webAppStats.getContextPath()
265:                        + " (" + webAppStats.getServletContextName() + ')');
266:                out.println();
267:                out.println("# active sessions:\t"
268:                        + numberFormat.format(webAppStats
269:                                .getActiveSessionsCount()));
270:                out.println("# passive sessions:\t"
271:                        + numberFormat.format(webAppStats
272:                                .getPassiveSessionsCount()));
273:                out.println("Total sessions size:\t"
274:                        + bytesFormat.format(webAppStats
275:                                .getActiveSessionsSize()));
276:                out.println("# created sessions:\t"
277:                        + numberFormat.format(webAppStats
278:                                .getTotalCreatedSessions()));
279:                out.println("max concurrent sessions:\t"
280:                        + numberFormat.format(webAppStats
281:                                .getMaxConcurrentSessions()));
282:                out.println();
283:                out.println("# hits:\t\t\t"
284:                        + numberFormat.format(webAppStats.getHits()));
285:                out.println("Mean requests size:\t"
286:                        + bytesFormat
287:                                .format(webAppStats.getRequestMeanLength()));
288:                out.println("Total requests size:\t"
289:                        + bytesFormat.format(webAppStats
290:                                .getRequestTotalLength()));
291:                out.println("Mean response size:\t"
292:                        + bytesFormat.format(webAppStats
293:                                .getResponseMeanLength()));
294:                out.println("Total response size:\t"
295:                        + bytesFormat.format(webAppStats
296:                                .getResponseTotalLength()));
297:                out.println();
298:                // ServletContext attributes
299:                Map attributes = webAppStats.getAttributes();
300:                out.println("# attributes:\t"
301:                        + numberFormat.format(attributes.size()));
302:                Iterator iter = attributes.entrySet().iterator();
303:                while (iter.hasNext()) {
304:                    Map.Entry entry = (Map.Entry) iter.next();
305:                    out.println("\tAttribute name:\t" + entry.getKey());
306:                    out.println("\tAttribute Class:\t"
307:                            + (entry.getValue() != null ? entry.getValue()
308:                                    .getClass().getName() : ""));
309:                    out.println("\tAttribute size:\t"
310:                            + bytesFormat.format(SizeOfProvider.Util
311:                                    .getObjectSize(entry.getValue(),
312:                                            webAppStats.getClassLoader())));
313:                    out.println();
314:                }
315:                out.close();
316:            }
317:
318:            /* (non-Javadoc)
319:             * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayServerInfosPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
320:             */
321:            public void displayServerInfosPage(HttpServletRequest req,
322:                    HttpServletResponse resp, IServerInfo serverInfo)
323:                    throws ServletException, IOException {
324:                BytesFormat bytesFormat = new BytesFormat(I18NSupport
325:                        .getAdminLocale(), " ");//$NON-NLS-1$
326:                NumberFormat numberFormat = NumberFormat
327:                        .getNumberInstance(I18NSupport.getAdminLocale());
328:                DateFormat dateTimeFormat = DateFormat.getDateInstance(
329:                        DateFormat.DEFAULT, I18NSupport.getAdminLocale());
330:                ((SimpleDateFormat) dateTimeFormat)
331:                        .applyPattern(DATE_TIME_PATTERN);
332:                PrintWriter out = resp.getWriter();
333:                writeMenu(req, resp, out);
334:                out.println();
335:                out.println("Server Information");
336:                out.println();
337:                out.println("Startup time:\t"
338:                        + dateTimeFormat.format(serverInfo.getStartupTime()));
339:                out.println("# CPUs:\t\t"
340:                        + numberFormat.format(serverInfo.getCpuCount()));
341:                out.println("Free memory:\t"
342:                        + bytesFormat.format(serverInfo.getFreeMemory()));
343:                out.println("Total memory:\t"
344:                        + bytesFormat.format(serverInfo.getTotalMemory()));
345:                if (serverInfo.getTotalMemory() >= 0) {
346:                    out.println("Max memory:\t"
347:                            + bytesFormat.format(serverInfo.getMaxMemory()));
348:                }
349:                out.close();
350:            }
351:
352:            protected void writeMenu(HttpServletRequest req,
353:                    HttpServletResponse resp, PrintWriter out) {
354:                out.print("Server information:\t");
355:                out.println(resp.encodeURL(req.getRequestURL().append(
356:                        "?action=serverInfos&format=").append(getFormatID())
357:                        .toString()));
358:                out.print("Applications list:\t");
359:                out.println(resp.encodeURL(req.getRequestURL().append(
360:                        "?action=webAppsList&format=").append(getFormatID())
361:                        .toString()));
362:            }
363:
364:            protected void writeMenu(HttpServletRequest req,
365:                    HttpServletResponse resp, PrintWriter out,
366:                    IApplicationInfo app) {
367:                out.print("Application stats:\t");
368:                out.println(resp.encodeURL(req.getRequestURL().append(
369:                        "?context=").append(app.getInternalContextPath())
370:                        .append("&action=webAppStats&format=").append(
371:                                getFormatID()).toString()));
372:                out.print("Sessions list:\t");
373:                out.println(resp.encodeURL(req.getRequestURL().append(
374:                        "?context=").append(app.getInternalContextPath())
375:                        .append("&action=sessionsList&format=").append(
376:                                getFormatID()).toString()));
377:            }
378:
379:            protected void writeMenu(HttpServletRequest req,
380:                    HttpServletResponse resp, PrintWriter out,
381:                    IApplicationInfo app, ISessionInfo session) {
382:                out.print("Session details:\t");
383:                out.println(resp.encodeURL(req.getRequestURL().append(
384:                        "?context=").append(app.getInternalContextPath())
385:                        .append("&action=sessionDetail&sessionId=").append(
386:                                session.getId()).append("&format=").append(
387:                                getFormatID()).toString()));
388:            }
389:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.