Source Code Cross Referenced for ConnectorStats.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » tomcat » stats » 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 » EJB Server geronimo » plugins » org.apache.geronimo.tomcat.stats 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.tomcat.stats;
017:
018:        import java.util.Iterator;
019:        import java.util.Set;
020:
021:        import javax.management.MBeanServer;
022:        import javax.management.ObjectInstance;
023:        import javax.management.ObjectName;
024:        import javax.management.j2ee.statistics.Stats;
025:        import org.apache.geronimo.management.geronimo.stats.TomcatWebConnectorStatsImpl;
026:
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:        import org.apache.tomcat.util.modeler.Registry;
030:
031:        /**
032:         * This will query MBeanServer and provide jsr77 Stats for connectors.
033:         * 
034:         * @version $Revision: 603663 $ $Date: 2007-12-12 08:23:47 -0800 (Wed, 12 Dec 2007) $
035:         */
036:        public class ConnectorStats {
037:            private static final Log log = LogFactory
038:                    .getLog(ConnectorStats.class);
039:            protected MBeanServer mBeanServer = null;
040:
041:            protected Registry registry;
042:
043:            private ObjectName grpName;
044:
045:            private ObjectName tpName;
046:
047:            private TomcatWebConnectorStatsImpl stats = new TomcatWebConnectorStatsImpl();
048:
049:            public ConnectorStats() {
050:                // Retrieve the MBean server
051:                registry = Registry.getRegistry(null, null);
052:                mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
053:                try {
054:                    grpName = new ObjectName("*:type=GlobalRequestProcessor,*");
055:                    tpName = new ObjectName("*:type=ThreadPool,*");
056:                } catch (Exception ex) {
057:                    log.error("Error - " + ex.toString());
058:                }
059:            }
060:
061:            public Stats getStats(String port) {
062:                stats.setStartTime();
063:                updateStats(stats, port);
064:                return stats;
065:
066:            }
067:
068:            public Stats updateStats(String port) {
069:                updateStats(stats, port);
070:                return stats;
071:
072:            }
073:
074:            private void updateStats(TomcatWebConnectorStatsImpl stats,
075:                    String port) {
076:                Iterator iterator;
077:                Set set;
078:                ObjectName objectName;
079:                try {
080:                    // Query Thread Pools
081:                    set = mBeanServer.queryMBeans(tpName, null);
082:                    iterator = set.iterator();
083:                    while (iterator.hasNext()) {
084:                        ObjectInstance oi = (ObjectInstance) iterator.next();
085:                        objectName = oi.getObjectName();
086:                        if (objectName.getKeyProperty("name").indexOf(port) > -1) {
087:                            tpName = objectName;
088:                            break;
089:                        }
090:                    }
091:                    // Query Global Request Processors
092:                    set = mBeanServer.queryMBeans(grpName, null);
093:                    iterator = set.iterator();
094:                    while (iterator.hasNext()) {
095:                        ObjectInstance oi = (ObjectInstance) iterator.next();
096:                        objectName = oi.getObjectName();
097:                        if (objectName.getKeyProperty("name").indexOf(port) > -1) {
098:                            grpName = objectName;
099:                            break;
100:                        }
101:                    }
102:                    stats.setLastSampleTime();
103:                    // Any http connector !
104:                    long maxTime = ((Long) (mBeanServer.getAttribute(grpName,
105:                            "maxTime"))).longValue();
106:                    long processingTime = ((Long) (mBeanServer.getAttribute(
107:                            grpName, "processingTime"))).longValue();
108:                    int requestCount = ((Integer) (mBeanServer.getAttribute(
109:                            grpName, "requestCount"))).intValue();
110:                    int errorCount = ((Integer) (mBeanServer.getAttribute(
111:                            grpName, "errorCount"))).intValue();
112:                    long bytesReceived = ((Long) (mBeanServer.getAttribute(
113:                            grpName, "bytesReceived"))).longValue();
114:                    long bytesSent = ((Long) (mBeanServer.getAttribute(grpName,
115:                            "bytesSent"))).longValue();
116:                    // Tomcat does not keep min Time, using 0 as Undefined value
117:                    stats.setRequestTime(requestCount, 0, maxTime,
118:                            processingTime);
119:                    stats.setErrorCount(errorCount);
120:                    stats.setBytesSentCount(bytesSent);
121:                    stats.setBytesReceivedCount(bytesReceived);
122:                    long openConnections = 0;
123:                    // TODO find these
124:                    //long openConnections = ((Long) (mBeanServer.getAttribute(grpName, "countOpenConnections"))).longValue();
125:                    long maxOpenConnections = 0;
126:                    //long maxOpenConnections = ((Long) (mBeanServer.getAttribute(grpName, "maxOpenConnections"))).longValue();
127:                    stats.setOpenConnection(openConnections,
128:                            maxOpenConnections, 0);
129:                    // ThreadPool 
130:                    int currentThreadsBusy = ((Integer) (mBeanServer
131:                            .getAttribute(tpName, "currentThreadsBusy")))
132:                            .intValue();
133:                    //stats.setActiveRequestCount(currentThreadsBusy); ??
134:                    int currentThreadCount = ((Integer) (mBeanServer
135:                            .getAttribute(tpName, "currentThreadCount")))
136:                            .intValue();
137:                    // these are available from "*:type=Connector,*"
138:                    //int minSpareThreads = ((Integer) (mBeanServer.getAttribute(tpName, "minSpareThreads"))).intValue();
139:                    //int maxSpareThreads = ((Integer) (mBeanServer.getAttribute(tpName, "maxSpareThreads"))).intValue();
140:                    int maxThreads = ((Integer) (mBeanServer.getAttribute(
141:                            tpName, "maxThreads"))).intValue();
142:                    // keepAliveCount is also available
143:                    stats.setBusyThreads(currentThreadsBusy,
144:                            currentThreadCount, 0, maxThreads, 0);
145:                    // TODO - spareThreads (current-busy, maxSpareThread, minSpareThreads)
146:                } catch (Exception ex) {
147:                    log.error("Error getting attribute " + grpName + " "
148:                            + ex.toString());
149:                }
150:
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.