Source Code Cross Referenced for SnapshotThread.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » monitoring » snapshot » 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.monitoring.snapshot 
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.monitoring.snapshot;
017:
018:        import java.util.ArrayList;
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.Set;
022:
023:        import javax.management.MBeanServer;
024:        import javax.management.ObjectName;
025:
026:        import org.apache.geronimo.monitoring.MasterRemoteControlJMX;
027:
028:        /**
029:         * Thread that is in charge of executing every x milliseconds. Upon each
030:         * iteration, a snapshot of the server's information is recorded.
031:         */
032:        public class SnapshotThread extends Thread {
033:
034:            private long SNAPSHOT_DURATION;
035:            private MBeanServer mbServer = null;
036:            int threadStatus = 1;
037:            // list of mbean names that we will be taking snapshots of
038:            private ArrayList<String> mbeanNames;
039:
040:            public SnapshotThread(long snapshot_length, MBeanServer mbServer) {
041:                SNAPSHOT_DURATION = snapshot_length;
042:                this .mbServer = mbServer;
043:                mbeanNames = new ArrayList<String>();
044:            }
045:
046:            /**
047:             * Gets the elapsed time in milliseconds between each snapshot.
048:             * 
049:             * @return long
050:             */
051:            public long getSnapshotDuration() {
052:                return SNAPSHOT_DURATION;
053:            }
054:
055:            public Integer SnapshotStatus() {
056:                return threadStatus;
057:
058:            }
059:
060:            /**
061:             * Adds the mbean name to list in memory. To update the snapshot-config.xml
062:             * coder must use SnapshotConfigXMLBuilder class.
063:             * 
064:             * @param mbeanName
065:             */
066:            public void addMBeanForSnapshot(String mbeanName) {
067:                mbeanNames.add(mbeanName);
068:            }
069:
070:            /**
071:             * Removes the mbean name to list in memory. To update the
072:             * snapshot-config.xml coder must use SnapshotConfigXMLBuilder class.
073:             * 
074:             * @param mbeanName
075:             */
076:            public void removeMBeanForSnapshot(String mbeanName) {
077:                mbeanNames.remove(mbeanName);
078:            }
079:
080:            /**
081:             * Sets the elapsed time in milliseconds between each snapshot.
082:             * 
083:             * @param snapshotDuration
084:             */
085:            public void setSnapshotDuration(long snapshot_length) {
086:                SNAPSHOT_DURATION = snapshot_length;
087:                if (snapshot_length == Long.MAX_VALUE)
088:                    threadStatus = -1;
089:            }
090:
091:            public void run() {
092:                // get any saved mbean names from snapshot-config.xml
093:                mbeanNames = SnapshotConfigXMLBuilder.getMBeanNames();
094:                // in the case where nothing is present, grab a set of default mbeans
095:                if (mbeanNames.size() <= 0) {
096:                    mbeanNames = getDefaultMBeanList();
097:                }
098:                // pause the thread from running every SNAPSHOT_DURATION seconds
099:                while (true && SNAPSHOT_DURATION != Long.MAX_VALUE) {
100:                    try {
101:                        // store the data
102:                        SnapshotProcessor.takeSnapshot();
103:                        // wait for next snapshot
104:                        Thread.sleep(SNAPSHOT_DURATION);
105:                    } catch (Exception e) {
106:                        e.printStackTrace();
107:                    }
108:                }
109:                // flag turned on to know when the thread stops
110:                threadStatus = 0;
111:            }
112:
113:            /**
114:             * @return A list of all default mbeans; namely, all connector or container
115:             *         mbean names Prereq: in order to be a connector or container mbean
116:             *         the name must contain "Connector"/"Container" and
117:             *         "Tomcat"/"Jetty"
118:             */
119:            private ArrayList<String> getDefaultMBeanList() {
120:                Set<String> mbeans = (new MasterRemoteControlJMX())
121:                        .getStatisticsProviderMBeanNames();
122:                ArrayList<String> retval = new ArrayList<String>();
123:                for (Iterator it = mbeans.iterator(); it.hasNext();) {
124:                    String name = (String) it.next();
125:                    if ((name.contains("Connector") || name
126:                            .contains("Container"))
127:                            && (name.contains("Jetty") || name
128:                                    .contains("Tomcat"))) {
129:                        // this is a connector, so add to the list
130:                        retval.add(name);
131:                        // update the snapshot-config.xml to include these
132:                        SnapshotConfigXMLBuilder.addMBeanName(name);
133:                    }
134:                }
135:                return retval;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.