Source Code Cross Referenced for StageMonitorImpl.java in  » Net » Terracotta » com » tc » async » impl » 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 » Net » Terracotta » com.tc.async.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.async.impl;
005:
006:        import com.tc.async.api.StageMonitor;
007:        import com.tc.text.StringFormatter;
008:
009:        import java.util.ArrayList;
010:        import java.util.Iterator;
011:        import java.util.List;
012:
013:        class StageMonitorImpl implements  StageMonitor {
014:
015:            private final String name;
016:            private final StringFormatter formatter;
017:
018:            private final List snapshots = new ArrayList();
019:            private long begin = System.currentTimeMillis();
020:
021:            StageMonitorImpl(String name, StringFormatter formatter) {
022:                this .name = formatter.rightPad(30, name);
023:                this .formatter = formatter;
024:            }
025:
026:            public synchronized void eventBegin(int queueDepth) {
027:                snapshots.add(new Snapshot(queueDepth));
028:            }
029:
030:            public synchronized String dumpAndFlush() {
031:                long elapsed = System.currentTimeMillis() - begin;
032:                StringBuffer rv = new StringBuffer();
033:                dump(elapsed, rv);
034:                flush();
035:                return rv.toString();
036:            }
037:
038:            private StringBuffer dump(long elapsed, StringBuffer buf) {
039:                Analysis an = analyze();
040:                buf.append(name).append("| period: ").append(
041:                        formatter.leftPad(10, an.getElapsedTime())).append(
042:                        "ms.| events: ").append(
043:                        formatter.leftPad(10, an.getEventCount()));
044:
045:                buf.append("| events/sec: ").append(
046:                        formatter.leftPad(10, an.getEventsPerSecond()));
047:
048:                buf.append("| Q depth, min: ").append(
049:                        formatter.leftPad(10, an.getMinQueueDepth()));
050:                buf.append(", max: ").append(
051:                        formatter.leftPad(10, an.getMaxQueueDepth()));
052:                buf.append(", avg: ").append(
053:                        formatter.leftPad(10, an.getAvgQueueDepth()));
054:
055:                return buf;
056:            }
057:
058:            // XXX: Yeah, I know this is dumb.
059:            private Double safeDiv(long numerator, long denominator) {
060:                if (denominator > 0) {
061:                    return new Double(((double) numerator)
062:                            / ((double) denominator));
063:                } else {
064:                    return new Double(-1);
065:                }
066:            }
067:
068:            public synchronized Analysis analyze() {
069:                long elapsed = System.currentTimeMillis() - begin;
070:                int min = -1, max = 0;
071:                long sum = 0;
072:                for (Iterator i = snapshots.iterator(); i.hasNext();) {
073:                    int qd = ((Snapshot) i.next()).getQueueDepth();
074:                    if (qd < min || min < 0)
075:                        min = qd;
076:                    if (qd > max)
077:                        max = qd;
078:                    sum += qd;
079:                }
080:
081:                return new AnalysisImpl(new Long(elapsed), new Integer(
082:                        snapshots.size()), safeDiv(snapshots.size() * 1000,
083:                        elapsed), new Integer(min), new Integer(max), safeDiv(
084:                        sum, snapshots.size()));
085:            }
086:
087:            public synchronized void flush() {
088:                snapshots.clear();
089:                begin = System.currentTimeMillis();
090:            }
091:
092:            public static class AnalysisImpl implements  Analysis {
093:                private final Number eventCount;
094:                private final Number eventsPerSecond;
095:                private final Number minQueueDepth;
096:                private final Number maxQueueDepth;
097:                private final Number avgQueueDepth;
098:                private final Number elapsedTime;
099:
100:                private AnalysisImpl(Number elapsedTime, Number eventCount,
101:                        Number eventsPerSecond, Number minQueueDepth,
102:                        Number maxQueueDepth, Number avgQueueDepth) {
103:                    this .elapsedTime = elapsedTime;
104:                    this .eventCount = eventCount;
105:                    this .eventsPerSecond = eventsPerSecond;
106:                    this .minQueueDepth = minQueueDepth;
107:                    this .maxQueueDepth = maxQueueDepth;
108:                    this .avgQueueDepth = avgQueueDepth;
109:                }
110:
111:                public Number getElapsedTime() {
112:                    return elapsedTime;
113:                }
114:
115:                public Number getAvgQueueDepth() {
116:                    return avgQueueDepth;
117:                }
118:
119:                public Number getMaxQueueDepth() {
120:                    return maxQueueDepth;
121:                }
122:
123:                public Number getMinQueueDepth() {
124:                    return minQueueDepth;
125:                }
126:
127:                public Number getEventsPerSecond() {
128:                    return eventsPerSecond;
129:                }
130:
131:                public Number getEventCount() {
132:                    return eventCount;
133:                }
134:
135:            }
136:
137:            private static class Snapshot {
138:                private final int queueDepth;
139:
140:                private Snapshot(int queueDepth) {
141:                    this .queueDepth = queueDepth;
142:                }
143:
144:                public int getQueueDepth() {
145:                    return queueDepth;
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.