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


001:        /*
002:         * Copyright 2003-2006 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:
026:        package com.sun.management;
027:
028:        import java.lang.management.MemoryUsage;
029:        import javax.management.openmbean.CompositeData;
030:        import javax.management.openmbean.CompositeDataView;
031:        import javax.management.openmbean.CompositeType;
032:        import java.util.Collection;
033:        import java.util.Collections;
034:        import java.util.HashMap;
035:        import java.util.Map;
036:        import java.util.List;
037:        import sun.management.GcInfoCompositeData;
038:        import sun.management.GcInfoBuilder;
039:
040:        /**
041:         * Garbage collection information.  It contains the following 
042:         * information for one garbage collection as well as GC-specific
043:         * attributes:
044:         * <blockquote>
045:         * <ul>
046:         *   <li>Start time</li>
047:         *   <li>End time</li>
048:         *   <li>Duration</li>
049:         *   <li>Memory usage before the collection starts</li>
050:         *   <li>Memory usage after the collection ends</li>
051:         * </ul>
052:         * </blockquote>
053:         *
054:         * <p>
055:         * <tt>GcInfo</tt> is a {@link CompositeData CompositeData}
056:         * The GC-specific attributes can be obtained via the CompositeData
057:         * interface.  This is a historical relic, and other classes should
058:         * not copy this pattern.  Use {@link CompositeDataView} instead.
059:         *
060:         * <h4>MXBean Mapping</h4>
061:         * <tt>GcInfo</tt> is mapped to a {@link CompositeData CompositeData}
062:         * with attributes as specified in the {@link #from from} method.
063:         *
064:         * @author  Mandy Chung
065:         * @version 1.15, 05/05/07
066:         * @since   1.5
067:         */
068:        public class GcInfo implements  CompositeData, CompositeDataView {
069:            private final long index;
070:            private final long startTime;
071:            private final long endTime;
072:            private final Map<String, MemoryUsage> usageBeforeGc;
073:            private final Map<String, MemoryUsage> usageAfterGc;
074:            private final Object[] extAttributes;
075:            private final CompositeData cdata;
076:            private final GcInfoBuilder builder;
077:
078:            private GcInfo(GcInfoBuilder builder, long index, long startTime,
079:                    long endTime, MemoryUsage[] muBeforeGc,
080:                    MemoryUsage[] muAfterGc, Object[] extAttributes) {
081:                this .builder = builder;
082:                this .index = index;
083:                this .startTime = startTime;
084:                this .endTime = endTime;
085:                String[] poolNames = builder.getPoolNames();
086:                this .usageBeforeGc = new HashMap<String, MemoryUsage>(
087:                        poolNames.length);
088:                this .usageAfterGc = new HashMap<String, MemoryUsage>(
089:                        poolNames.length);
090:                for (int i = 0; i < poolNames.length; i++) {
091:                    this .usageBeforeGc.put(poolNames[i], muBeforeGc[i]);
092:                    this .usageAfterGc.put(poolNames[i], muAfterGc[i]);
093:                }
094:                this .extAttributes = extAttributes;
095:                this .cdata = new GcInfoCompositeData(this , builder,
096:                        extAttributes);
097:            }
098:
099:            private GcInfo(CompositeData cd) {
100:                GcInfoCompositeData.validateCompositeData(cd);
101:
102:                this .index = GcInfoCompositeData.getId(cd);
103:                this .startTime = GcInfoCompositeData.getStartTime(cd);
104:                this .endTime = GcInfoCompositeData.getEndTime(cd);
105:                this .usageBeforeGc = GcInfoCompositeData
106:                        .getMemoryUsageBeforeGc(cd);
107:                this .usageAfterGc = GcInfoCompositeData
108:                        .getMemoryUsageAfterGc(cd);
109:                this .extAttributes = null;
110:                this .builder = null;
111:                this .cdata = cd;
112:            }
113:
114:            /**
115:             * Returns the identifier of this garbage collection which is
116:             * the number of collections that this collector has done.
117:             *
118:             * @return the identifier of this garbage collection which is
119:             * the number of collections that this collector has done.
120:             */
121:            public long getId() {
122:                return index;
123:            }
124:
125:            /**
126:             * Returns the start time of this GC in milliseconds
127:             * since the Java virtual machine was started.
128:             *
129:             * @return the start time of this GC.
130:             */
131:            public long getStartTime() {
132:                return startTime;
133:            }
134:
135:            /**
136:             * Returns the end time of this GC in milliseconds
137:             * since the Java virtual machine was started.
138:             *
139:             * @return the end time of this GC.
140:             */
141:            public long getEndTime() {
142:                return endTime;
143:            }
144:
145:            /**
146:             * Returns the elapsed time of this GC in milliseconds.
147:             *
148:             * @return the elapsed time of this GC in milliseconds.
149:             */
150:            public long getDuration() {
151:                return endTime - startTime;
152:            }
153:
154:            /**
155:             * Returns the memory usage of all memory pools 
156:             * at the beginning of this GC.
157:             * This method returns
158:             * a <tt>Map</tt> of the name of a memory pool 
159:             * to the memory usage of the corresponding 
160:             * memory pool before GC starts.
161:             *
162:             * @return a <tt>Map</tt> of memory pool names to the memory
163:             * usage of a memory pool before GC starts.
164:             */
165:            public Map<String, MemoryUsage> getMemoryUsageBeforeGc() {
166:                return Collections.unmodifiableMap(usageBeforeGc);
167:            }
168:
169:            /**
170:             * Returns the memory usage of all memory pools
171:             * at the end of this GC.
172:             * This method returns
173:             * a <tt>Map</tt> of the name of a memory pool 
174:             * to the memory usage of the corresponding 
175:             * memory pool when GC finishes.
176:             *
177:             * @return a <tt>Map</tt> of memory pool names to the memory
178:             * usage of a memory pool when GC finishes.
179:             */
180:            public Map<String, MemoryUsage> getMemoryUsageAfterGc() {
181:                return Collections.unmodifiableMap(usageAfterGc);
182:            }
183:
184:            /**
185:             * Returns a <tt>GcInfo</tt> object represented by the
186:             * given <tt>CompositeData</tt>. The given
187:             * <tt>CompositeData</tt> must contain
188:             * all the following attributes:
189:             *
190:             * <p>
191:             * <blockquote>
192:             * <table border>
193:             * <tr>
194:             *   <th align=left>Attribute Name</th>
195:             *   <th align=left>Type</th>
196:             * </tr>
197:             * <tr>
198:             *   <td>index</td>
199:             *   <td><tt>java.lang.Long</tt></td>
200:             * </tr>
201:             * <tr>
202:             *   <td>startTime</td>
203:             *   <td><tt>java.lang.Long</tt></td>
204:             * </tr>
205:             * <tr>
206:             *   <td>endTime</td>
207:             *   <td><tt>java.lang.Long</tt></td>
208:             * </tr>
209:             * <tr>
210:             *   <td>memoryUsageBeforeGc</td>
211:             *   <td><tt>javax.management.openmbean.TabularData</tt></td>
212:             * </tr>
213:             * <tr>
214:             *   <td>memoryUsageAfterGc</td>
215:             *   <td><tt>javax.management.openmbean.TabularData</tt></td>
216:             * </tr>
217:             * </table>
218:             * </blockquote>
219:             *
220:             * @throws IllegalArgumentException if <tt>cd</tt> does not
221:             *   represent a <tt>GcInfo</tt> object with the attributes
222:             *   described above.
223:             *
224:             * @return a <tt>GcInfo</tt> object represented by <tt>cd</tt>
225:             * if <tt>cd</tt> is not <tt>null</tt>; <tt>null</tt> otherwise.
226:             */
227:            public static GcInfo from(CompositeData cd) {
228:                if (cd == null) {
229:                    return null;
230:                }
231:
232:                if (cd instanceof  GcInfoCompositeData) {
233:                    return ((GcInfoCompositeData) cd).getGcInfo();
234:                } else {
235:                    return new GcInfo(cd);
236:                }
237:
238:            }
239:
240:            // Implementation of the CompositeData interface
241:            public boolean containsKey(String key) {
242:                return cdata.containsKey(key);
243:            }
244:
245:            public boolean containsValue(Object value) {
246:                return cdata.containsValue(value);
247:            }
248:
249:            public boolean equals(Object obj) {
250:                return cdata.equals(obj);
251:            }
252:
253:            public Object get(String key) {
254:                return cdata.get(key);
255:            }
256:
257:            public Object[] getAll(String[] keys) {
258:                return cdata.getAll(keys);
259:            }
260:
261:            public CompositeType getCompositeType() {
262:                return cdata.getCompositeType();
263:            }
264:
265:            public int hashCode() {
266:                return cdata.hashCode();
267:            }
268:
269:            public String toString() {
270:                return cdata.toString();
271:            }
272:
273:            public Collection values() {
274:                return cdata.values();
275:            }
276:
277:            /**
278:             * <p>Return the {@code CompositeData} representation of this
279:             * {@code GcInfo}, including any GC-specific attributes.  The
280:             * returned value will have at least all the attributes described
281:             * in the {@link #from(CompositeData) from} method, plus optionally
282:             * other attributes.
283:             *
284:             * @param ct the {@code CompositeType} that the caller expects.
285:             * This parameter is ignored and can be null.
286:             *
287:             * @return the {@code CompositeData} representation.
288:             */
289:            public CompositeData toCompositeData(CompositeType ct) {
290:                return cdata;
291:            }
292:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.