Source Code Cross Referenced for GcInfoBuilder.java in  » 6.0-JDK-Modules-sun » management » sun » management » 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 » 6.0 JDK Modules sun » management » sun.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:        package sun.management;
026:
027:        import java.lang.management.GarbageCollectorMXBean;
028:        import java.lang.management.MemoryUsage;
029:        import javax.management.openmbean.OpenType;
030:        import javax.management.openmbean.SimpleType;
031:        import javax.management.openmbean.TabularType;
032:        import javax.management.openmbean.TabularData;
033:        import javax.management.openmbean.TabularDataSupport;
034:        import javax.management.openmbean.CompositeType;
035:        import javax.management.openmbean.CompositeData;
036:        import javax.management.openmbean.CompositeDataSupport;
037:        import javax.management.openmbean.OpenDataException;
038:        import com.sun.management.GcInfo;
039:
040:        /**
041:         * Helper class to build composite data.
042:         */
043:        public class GcInfoBuilder {
044:            private final GarbageCollectorMXBean gc;
045:            private final String[] poolNames;
046:            private String[] allItemNames;
047:
048:            // GC-specific composite type:
049:            // Each GarbageCollectorMXBean may have different GC-specific attributes
050:            // the CompositeType for the GcInfo could be different.
051:            private CompositeType gcInfoCompositeType;
052:
053:            // GC-specific items 
054:            private final int gcExtItemCount;
055:            private final String[] gcExtItemNames;
056:            private final String[] gcExtItemDescs;
057:            private final char[] gcExtItemTypes;
058:
059:            GcInfoBuilder(GarbageCollectorMXBean gc, String[] poolNames) {
060:                this .gc = gc;
061:                this .poolNames = poolNames;
062:                this .gcExtItemCount = getNumGcExtAttributes(gc);
063:                this .gcExtItemNames = new String[gcExtItemCount];
064:                this .gcExtItemDescs = new String[gcExtItemCount];
065:                this .gcExtItemTypes = new char[gcExtItemCount];
066:
067:                // Fill the information about extension attributes
068:                fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames,
069:                        gcExtItemTypes, gcExtItemDescs);
070:
071:                // lazily build the CompositeType for the GcInfo
072:                // including the GC-specific extension attributes
073:                this .gcInfoCompositeType = null;
074:            }
075:
076:            GcInfo getLastGcInfo() {
077:                MemoryUsage[] usageBeforeGC = new MemoryUsage[poolNames.length];
078:                MemoryUsage[] usageAfterGC = new MemoryUsage[poolNames.length];
079:                Object[] values = new Object[gcExtItemCount];
080:
081:                return getLastGcInfo0(gc, gcExtItemCount, values,
082:                        gcExtItemTypes, usageBeforeGC, usageAfterGC);
083:            }
084:
085:            public String[] getPoolNames() {
086:                return poolNames;
087:            }
088:
089:            int getGcExtItemCount() {
090:                return gcExtItemCount;
091:            }
092:
093:            // Returns the CompositeType for the GcInfo including 
094:            // the extension attributes
095:            synchronized CompositeType getGcInfoCompositeType() {
096:                if (gcInfoCompositeType != null)
097:                    return gcInfoCompositeType;
098:
099:                // First, fill with the attributes in the GcInfo
100:                String[] gcInfoItemNames = GcInfoCompositeData
101:                        .getBaseGcInfoItemNames();
102:                OpenType[] gcInfoItemTypes = GcInfoCompositeData
103:                        .getBaseGcInfoItemTypes();
104:                int numGcInfoItems = gcInfoItemNames.length;
105:
106:                int itemCount = numGcInfoItems + gcExtItemCount;
107:                allItemNames = new String[itemCount];
108:                String[] allItemDescs = new String[itemCount];
109:                OpenType[] allItemTypes = new OpenType[itemCount];
110:
111:                System.arraycopy(gcInfoItemNames, 0, allItemNames, 0,
112:                        numGcInfoItems);
113:                System.arraycopy(gcInfoItemNames, 0, allItemDescs, 0,
114:                        numGcInfoItems);
115:                System.arraycopy(gcInfoItemTypes, 0, allItemTypes, 0,
116:                        numGcInfoItems);
117:
118:                // Then fill with the extension GC-specific attributes, if any.
119:                if (gcExtItemCount > 0) {
120:                    fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames,
121:                            gcExtItemTypes, gcExtItemDescs);
122:                    System.arraycopy(gcExtItemNames, 0, allItemNames,
123:                            numGcInfoItems, gcExtItemCount);
124:                    System.arraycopy(gcExtItemDescs, 0, allItemDescs,
125:                            numGcInfoItems, gcExtItemCount);
126:                    for (int i = numGcInfoItems, j = 0; j < gcExtItemCount; i++, j++) {
127:                        switch (gcExtItemTypes[j]) {
128:                        case 'Z':
129:                            allItemTypes[i] = SimpleType.BOOLEAN;
130:                            break;
131:                        case 'B':
132:                            allItemTypes[i] = SimpleType.BYTE;
133:                            break;
134:                        case 'C':
135:                            allItemTypes[i] = SimpleType.CHARACTER;
136:                            break;
137:                        case 'S':
138:                            allItemTypes[i] = SimpleType.SHORT;
139:                            break;
140:                        case 'I':
141:                            allItemTypes[i] = SimpleType.INTEGER;
142:                            break;
143:                        case 'J':
144:                            allItemTypes[i] = SimpleType.LONG;
145:                            break;
146:                        case 'F':
147:                            allItemTypes[i] = SimpleType.FLOAT;
148:                            break;
149:                        case 'D':
150:                            allItemTypes[i] = SimpleType.DOUBLE;
151:                            break;
152:                        default:
153:                            throw new InternalError("Unsupported type ["
154:                                    + gcExtItemTypes[i] + "]");
155:                        }
156:                    }
157:                }
158:
159:                CompositeType gict = null;
160:                try {
161:                    final String typeName = "sun.management." + gc.getName()
162:                            + ".GcInfoCompositeType";
163:
164:                    gict = new CompositeType(typeName,
165:                            "CompositeType for GC info for " + gc.getName(),
166:                            allItemNames, allItemDescs, allItemTypes);
167:                } catch (OpenDataException e) {
168:                    // shouldn't reach here
169:                    throw Util.newException(e);
170:                }
171:                gcInfoCompositeType = gict;
172:
173:                return gcInfoCompositeType;
174:            }
175:
176:            synchronized String[] getItemNames() {
177:                if (allItemNames == null) {
178:                    // initialize when forming the composite type
179:                    getGcInfoCompositeType();
180:                }
181:                return allItemNames;
182:            }
183:
184:            // Retrieve information about extension attributes
185:            private native int getNumGcExtAttributes(GarbageCollectorMXBean gc);
186:
187:            private native void fillGcAttributeInfo(GarbageCollectorMXBean gc,
188:                    int numAttributes, String[] attributeNames, char[] types,
189:                    String[] descriptions);
190:
191:            /**
192:             * Returns the last GcInfo
193:             * 
194:             * @param gc GarbageCollectorMXBean that the gc info is associated with.
195:             * @param numExtAtts number of extension attributes 
196:             * @param extAttValues Values of extension attributes to be filled.
197:             * @param before Memory usage before GC to be filled.
198:             * @param after Memory usage after GC to be filled.
199:             */
200:            private native GcInfo getLastGcInfo0(GarbageCollectorMXBean gc,
201:                    int numExtAtts, Object[] extAttValues, char[] extAttTypes,
202:                    MemoryUsage[] before, MemoryUsage[] after);
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.