KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > management > LockInfo


1 /*
2  * @(#)LockInfo.java 1.6 06/02/27
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang.management;
9
10 import javax.management.openmbean.CompositeData JavaDoc;
11 import java.util.concurrent.locks.*;
12 import java.beans.ConstructorProperties JavaDoc;
13
14 /**
15  * Information about a <em>lock</em>. A lock can be a built-in object monitor,
16  * an <em>ownable synchronizer</em>, or the {@link Condition Condition}
17  * object associated with synchronizers.
18  * <p>
19  * <a name="OwnableSynchronizer">An ownable synchronizer</a> is
20  * a synchronizer that may be exclusively owned by a thread and uses
21  * {@link AbstractOwnableSynchronizer AbstractOwnableSynchronizer}
22  * (or its subclass) to implement its synchronization property.
23  * {@link ReentrantLock ReentrantLock} and
24  * {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
25  * two examples of ownable synchronizers provided by the platform.
26  *
27  * <h4><a name="MappedType">MXBean Mapping</a></h4>
28  * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData}
29  * as specified in the <a HREF="../../../javax/management/MXBean.html#mapping-rules">
30  * type mapping rules</a> of {@linkplain javax.management.MXBean MXBeans}.
31  *
32  * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
33  * @see java.util.concurrent.locks.Condition
34  *
35  * @author Mandy Chung
36  * @version 1.6, 02/27/06
37  * @since 1.6
38  */

39
40 public class LockInfo {
41
42     private String JavaDoc className;
43     private int identityHashCode;
44     
45     /**
46      * Constructs a <tt>LockInfo</tt> object.
47      *
48      * @param className the fully qualified name of the class of the lock object.
49      * @param identityHashCode the {@link System#identityHashCode
50      * identity hash code} of the lock object.
51      */

52     @ConstructorProperties JavaDoc({"className", "identityHashCode"})
53     public LockInfo(String JavaDoc className, int identityHashCode) {
54         if (className == null) {
55             throw new NullPointerException JavaDoc("Parameter className cannot be null");
56         }
57         this.className = className;
58         this.identityHashCode = identityHashCode;
59     }
60
61     /**
62      * package-private constructors
63      */

64     LockInfo(Object JavaDoc lock) {
65         this.className = lock.getClass().getName();
66         this.identityHashCode = System.identityHashCode(lock);
67     }
68
69     /**
70      * Returns the fully qualified name of the class of the lock object.
71      *
72      * @return the fully qualified name of the class of the lock object.
73      */

74     public String JavaDoc getClassName() {
75         return className;
76     }
77
78     /**
79      * Returns the identity hash code of the lock object
80      * returned from the {@link System#identityHashCode} method.
81      *
82      * @return the identity hash code of the lock object.
83      */

84     public int getIdentityHashCode() {
85         return identityHashCode;
86     }
87
88     /**
89      * Returns a string representation of a lock. The returned
90      * string representation consists of the name of the class of the
91      * lock object, the at-sign character `@', and the unsigned
92      * hexadecimal representation of the <em>identity</em> hash code
93      * of the object. This method returns a string equals to the value of:
94      * <blockquote>
95      * <pre>
96      * lock.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(lock))
97      * </pre></blockquote>
98      * where <tt>lock</tt> is the lock object.
99      *
100      * @return the string representation of a lock.
101      */

102     public String JavaDoc toString() {
103         return className + '@' + Integer.toHexString(identityHashCode);
104     }
105 }
106
Popular Tags