Source Code Cross Referenced for ActiveStatsMonitor.java in  » UML » MetaBoss » com » jamonapi » 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 » UML » MetaBoss » com.jamonapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi;
002:
003:        import java.util.*;
004:
005:        /** Tracks statistics for Monitors that are currently running.  The statistics tracked are how often this Monitor
006:         * is called (hits), how many outstanding invocations of start() have been called without a stop() for this instance (active), what
007:         * is the average number of active for this instance, and what was the maximum number of active for this instance.
008:         **/
009:
010:        public class ActiveStatsMonitor extends AccumulateMonitor {
011:            // ANY VARIABLES SET HERE MUST ALSO BE SET IN resetThis()!!!!
012:            private int max = Integer.MIN_VALUE;
013:            private int active;
014:            private int hits;
015:            private int total; // avg is calculated when needed by avg=total/hits
016:
017:            public ActiveStatsMonitor() {
018:                super ();
019:            }
020:
021:            /** Constructor that uses the Gang Of 4's decorator pattern. **/
022:            public ActiveStatsMonitor(AccumulateMonitorInterface childMonitor) {
023:                super (childMonitor);
024:            }
025:
026:            /** Adjust the statistics being tracked whenever start() is called.  For example whenever start() is called on this instance
027:             * the active variable is increased by 1.
028:             **/
029:            synchronized protected void startThis() {
030:                active++;
031:                hits++;
032:                total += active;
033:
034:                if (active > max)
035:                    max = active;
036:            }
037:
038:            /** Adjust the statistics being tracked whenever stop() is called.  For example whenever stop() is called on this instance
039:             * the active variable is decreased by 1.
040:             **/
041:
042:            synchronized protected void stopThis() {
043:                if (active > 0)
044:                    active--;
045:            }
046:
047:            protected void increaseThis(long increase) {
048:            }
049:
050:            /** Reset the variables for this instance to their default values **/
051:            synchronized protected void resetThis() {
052:                max = Integer.MIN_VALUE;
053:                hits = active = total = 0;
054:            }
055:
056:            /** Convert this Monitor to its String value for display purposes **/
057:            synchronized protected String toStringThis() {
058:                return getDisplayString(ACTIVE, convertToString(active), NONE)
059:                        + getDisplayString(AVGACTIVE, convertToString(avg()),
060:                                NONE)
061:                        + getDisplayString(MAXACTIVE, convertToString(max),
062:                                NONE);
063:            }
064:
065:            /** Add this instances data to the ArrayList.  This method is used to convert Monitor data to a tabular format **/
066:            synchronized protected void getDataThis(ArrayList rowData) {
067:                rowData.add(convertToString(active));
068:                rowData.add(convertToString(avg()));
069:                rowData.add(convertToString(max));
070:            }
071:
072:            /** Add this instances header to the ArrayList.  This method is used to convert Monitor header data to a tabular format. 
073:             *  The header will usually be used to display the Monitor in HTML format
074:             **/
075:            protected void getHeaderThis(ArrayList header) {
076:                header.add(ACTIVE);
077:                header.add(AVGACTIVE);
078:                header.add(MAXACTIVE);
079:            }
080:
081:            /** Return the average number of Active monitors of this instance **/
082:            final float avg() {
083:                if (hits == 0)
084:                    return 0;
085:                else
086:                    return (float) total / hits;
087:            }
088:
089:            /** Return the number of Active Monitors of this instance **/
090:            synchronized public long getAccrued() {
091:                return active;
092:            }
093:
094:            /** Method that contains test data for this class **/
095:            public static void main(String[] args) throws Exception {
096:                AccumulateMonitor mon = new ActiveStatsMonitor();
097:                System.out.println("should not have 0 divide error=" + mon);
098:                mon.start(); //active=1
099:                mon.start(); //2
100:                mon.start(); //3
101:                mon.stop(); //2
102:                mon.stop(); //1
103:                mon.start(); //2
104:
105:                System.out.println("should be active 2, avg 2, max active 3="
106:                        + mon);
107:
108:            }
109:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.