author | jfranck |
Wed, 11 Sep 2013 09:45:52 +0200 | |
changeset 19834 | c43d94c72c41 |
parent 18799 | 31062cb3cc8e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.management; |
|
27 |
||
28 |
import javax.management.openmbean.CompositeData; |
|
29 |
import java.util.concurrent.locks.*; |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
30 |
import sun.management.LockInfoCompositeData; |
2 | 31 |
|
32 |
/** |
|
33 |
* Information about a <em>lock</em>. A lock can be a built-in object monitor, |
|
34 |
* an <em>ownable synchronizer</em>, or the {@link Condition Condition} |
|
35 |
* object associated with synchronizers. |
|
36 |
* <p> |
|
37 |
* <a name="OwnableSynchronizer">An ownable synchronizer</a> is |
|
38 |
* a synchronizer that may be exclusively owned by a thread and uses |
|
39 |
* {@link AbstractOwnableSynchronizer AbstractOwnableSynchronizer} |
|
40 |
* (or its subclass) to implement its synchronization property. |
|
41 |
* {@link ReentrantLock ReentrantLock} and |
|
42 |
* {@link ReentrantReadWriteLock ReentrantReadWriteLock} are |
|
43 |
* two examples of ownable synchronizers provided by the platform. |
|
44 |
* |
|
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
14342
diff
changeset
|
45 |
* <h3><a name="MappedType">MXBean Mapping</a></h3> |
2 | 46 |
* <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData} |
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
47 |
* as specified in the {@link #from from} method. |
2 | 48 |
* |
49 |
* @see java.util.concurrent.locks.AbstractOwnableSynchronizer |
|
50 |
* @see java.util.concurrent.locks.Condition |
|
51 |
* |
|
52 |
* @author Mandy Chung |
|
53 |
* @since 1.6 |
|
54 |
*/ |
|
55 |
||
56 |
public class LockInfo { |
|
57 |
||
58 |
private String className; |
|
59 |
private int identityHashCode; |
|
60 |
||
61 |
/** |
|
62 |
* Constructs a <tt>LockInfo</tt> object. |
|
63 |
* |
|
64 |
* @param className the fully qualified name of the class of the lock object. |
|
65 |
* @param identityHashCode the {@link System#identityHashCode |
|
66 |
* identity hash code} of the lock object. |
|
67 |
*/ |
|
68 |
public LockInfo(String className, int identityHashCode) { |
|
69 |
if (className == null) { |
|
70 |
throw new NullPointerException("Parameter className cannot be null"); |
|
71 |
} |
|
72 |
this.className = className; |
|
73 |
this.identityHashCode = identityHashCode; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* package-private constructors |
|
78 |
*/ |
|
79 |
LockInfo(Object lock) { |
|
80 |
this.className = lock.getClass().getName(); |
|
81 |
this.identityHashCode = System.identityHashCode(lock); |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Returns the fully qualified name of the class of the lock object. |
|
86 |
* |
|
87 |
* @return the fully qualified name of the class of the lock object. |
|
88 |
*/ |
|
89 |
public String getClassName() { |
|
90 |
return className; |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Returns the identity hash code of the lock object |
|
95 |
* returned from the {@link System#identityHashCode} method. |
|
96 |
* |
|
97 |
* @return the identity hash code of the lock object. |
|
98 |
*/ |
|
99 |
public int getIdentityHashCode() { |
|
100 |
return identityHashCode; |
|
101 |
} |
|
102 |
||
103 |
/** |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
104 |
* Returns a {@code LockInfo} object represented by the |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
105 |
* given {@code CompositeData}. |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
106 |
* The given {@code CompositeData} must contain the following attributes: |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
107 |
* <blockquote> |
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
14342
diff
changeset
|
108 |
* <table border summary="The attributes and the types the given CompositeData contains"> |
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
109 |
* <tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
110 |
* <th align=left>Attribute Name</th> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
111 |
* <th align=left>Type</th> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
112 |
* </tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
113 |
* <tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
114 |
* <td>className</td> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
115 |
* <td><tt>java.lang.String</tt></td> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
116 |
* </tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
117 |
* <tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
118 |
* <td>identityHashCode</td> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
119 |
* <td><tt>java.lang.Integer</tt></td> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
120 |
* </tr> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
121 |
* </table> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
122 |
* </blockquote> |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
123 |
* |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
124 |
* @param cd {@code CompositeData} representing a {@code LockInfo} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
125 |
* |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
126 |
* @throws IllegalArgumentException if {@code cd} does not |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
127 |
* represent a {@code LockInfo} with the attributes described |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
128 |
* above. |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
129 |
* @return a {@code LockInfo} object represented |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
130 |
* by {@code cd} if {@code cd} is not {@code null}; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
131 |
* {@code null} otherwise. |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
132 |
* |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
133 |
* @since 1.8 |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
134 |
*/ |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
135 |
public static LockInfo from(CompositeData cd) { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
136 |
if (cd == null) { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
137 |
return null; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
138 |
} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
139 |
|
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
140 |
if (cd instanceof LockInfoCompositeData) { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
141 |
return ((LockInfoCompositeData) cd).getLockInfo(); |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
142 |
} else { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
143 |
return LockInfoCompositeData.toLockInfo(cd); |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
144 |
} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
145 |
} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
146 |
|
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
147 |
/** |
2 | 148 |
* Returns a string representation of a lock. The returned |
149 |
* string representation consists of the name of the class of the |
|
150 |
* lock object, the at-sign character `@', and the unsigned |
|
151 |
* hexadecimal representation of the <em>identity</em> hash code |
|
152 |
* of the object. This method returns a string equals to the value of: |
|
153 |
* <blockquote> |
|
154 |
* <pre> |
|
155 |
* lock.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(lock)) |
|
156 |
* </pre></blockquote> |
|
157 |
* where <tt>lock</tt> is the lock object. |
|
158 |
* |
|
159 |
* @return the string representation of a lock. |
|
160 |
*/ |
|
161 |
public String toString() { |
|
162 |
return className + '@' + Integer.toHexString(identityHashCode); |
|
163 |
} |
|
164 |
} |