Source Code Cross Referenced for MonitorInfo.java in  » 6.0-JDK-Core » lang » java » lang » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » lang » java.lang.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2005-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 java.lang.management;
027
028        import javax.management.openmbean.CompositeData;
029        import sun.management.MonitorInfoCompositeData;
030
031        /**
032         * Information about an object monitor lock.  An object monitor is locked
033         * when entering a synchronization block or method on that object.
034         *
035         * <h4>MXBean Mapping</h4>
036         * <tt>MonitorInfo</tt> is mapped to a {@link CompositeData CompositeData}
037         * with attributes as specified in
038         * the {@link #from from} method.
039         *
040         * @author  Mandy Chung
041         * @version 1.11, 05/05/07
042         * @since   1.6
043         */
044        public class MonitorInfo extends LockInfo {
045
046            private int stackDepth;
047            private StackTraceElement stackFrame;
048
049            /**
050             * Construct a <tt>MonitorInfo</tt> object.
051             *
052             * @param className the fully qualified name of the class of the lock object.
053             * @param identityHashCode the {@link System#identityHashCode
054             *                         identity hash code} of the lock object.
055             * @param stackDepth the depth in the stack trace where the object monitor
056             *                   was locked.
057             * @param stackFrame the stack frame that locked the object monitor.
058             * @throws IllegalArgumentException if 
059             *    <tt>stackDepth</tt> &ge; 0 but <tt>stackFrame</tt> is <tt>null</tt>,
060             *    or <tt>stackDepth</tt> &lt; 0 but <tt>stackFrame</tt> is not
061             *       <tt>null</tt>.
062             */
063            public MonitorInfo(String className, int identityHashCode,
064                    int stackDepth, StackTraceElement stackFrame) {
065                super (className, identityHashCode);
066                if (stackDepth >= 0 && stackFrame == null) {
067                    throw new IllegalArgumentException(
068                            "Parameter stackDepth is " + stackDepth
069                                    + " but stackFrame is null");
070                }
071                if (stackDepth < 0 && stackFrame != null) {
072                    throw new IllegalArgumentException(
073                            "Parameter stackDepth is " + stackDepth
074                                    + " but stackFrame is not null");
075                }
076                this .stackDepth = stackDepth;
077                this .stackFrame = stackFrame;
078            }
079
080            /**
081             * Returns the depth in the stack trace where the object monitor
082             * was locked.  The depth is the index to the <tt>StackTraceElement</tt>
083             * array returned in the {@link ThreadInfo#getStackTrace} method.
084             * 
085             * @return the depth in the stack trace where the object monitor
086             *         was locked, or a negative number if not available.
087             */
088            public int getLockedStackDepth() {
089                return stackDepth;
090            }
091
092            /**
093             * Returns the stack frame that locked the object monitor.
094             *
095             * @return <tt>StackTraceElement</tt> that locked the object monitor,
096             *         or <tt>null</tt> if not available.
097             */
098            public StackTraceElement getLockedStackFrame() {
099                return stackFrame;
100            }
101
102            /**
103             * Returns a <tt>MonitorInfo</tt> object represented by the
104             * given <tt>CompositeData</tt>.
105             * The given <tt>CompositeData</tt> must contain the following attributes
106             * as well as the attributes specified in the 
107             * <a href="LockInfo.html#MappedType">
108             * mapped type</a> for the {@link LockInfo} class: 
109             * <blockquote>
110             * <table border>
111             * <tr>
112             *   <th align=left>Attribute Name</th>
113             *   <th align=left>Type</th>
114             * </tr>
115             * <tr>
116             *   <td>lockedStackFrame</td>
117             *   <td><tt>CompositeData as specified in the 
118             *       <a href="ThreadInfo.html#StackTrace">stackTrace</a>
119             *       attribute defined in the {@link ThreadInfo#from
120             *       ThreadInfo.from} method.
121             *       </tt></td>
122             * </tr>
123             * <tr>
124             *   <td>lockedStackDepth</td>
125             *   <td><tt>java.lang.Integer</tt></td>
126             * </tr>
127             * </table>
128             * </blockquote>
129             *
130             * @param cd <tt>CompositeData</tt> representing a <tt>MonitorInfo</tt>
131             *
132             * @throws IllegalArgumentException if <tt>cd</tt> does not
133             *   represent a <tt>MonitorInfo</tt> with the attributes described
134             *   above.
135
136             * @return a <tt>MonitorInfo</tt> object represented
137             *         by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
138             *         <tt>null</tt> otherwise.
139             */
140            public static MonitorInfo from(CompositeData cd) {
141                if (cd == null) {
142                    return null;
143                }
144
145                if (cd instanceof  MonitorInfoCompositeData) {
146                    return ((MonitorInfoCompositeData) cd).getMonitorInfo();
147                } else {
148                    MonitorInfoCompositeData.validateCompositeData(cd);
149                    String className = MonitorInfoCompositeData
150                            .getClassName(cd);
151                    int identityHashCode = MonitorInfoCompositeData
152                            .getIdentityHashCode(cd);
153                    int stackDepth = MonitorInfoCompositeData
154                            .getLockedStackDepth(cd);
155                    StackTraceElement stackFrame = MonitorInfoCompositeData
156                            .getLockedStackFrame(cd);
157                    return new MonitorInfo(className, identityHashCode,
158                            stackDepth, stackFrame);
159                }
160            }
161
162        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.