jdk/src/share/classes/java/lang/management/LockInfo.java
changeset 13803 889df16bef60
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
13802:7e765d50416f 13803:889df16bef60
    25 
    25 
    26 package java.lang.management;
    26 package java.lang.management;
    27 
    27 
    28 import javax.management.openmbean.CompositeData;
    28 import javax.management.openmbean.CompositeData;
    29 import java.util.concurrent.locks.*;
    29 import java.util.concurrent.locks.*;
    30 import java.beans.ConstructorProperties;
    30 import sun.management.LockInfoCompositeData;
    31 
    31 
    32 /**
    32 /**
    33  * Information about a <em>lock</em>.  A lock can be a built-in object monitor,
    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}
    34  * an <em>ownable synchronizer</em>, or the {@link Condition Condition}
    35  * object associated with synchronizers.
    35  * object associated with synchronizers.
    42  * {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
    42  * {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
    43  * two examples of ownable synchronizers provided by the platform.
    43  * two examples of ownable synchronizers provided by the platform.
    44  *
    44  *
    45  * <h4><a name="MappedType">MXBean Mapping</a></h4>
    45  * <h4><a name="MappedType">MXBean Mapping</a></h4>
    46  * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData}
    46  * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData}
    47  * as specified in the <a href="../../../javax/management/MXBean.html#mapping-rules">
    47  * as specified in the {@link #from from} method.
    48  * type mapping rules</a> of {@linkplain javax.management.MXBean MXBeans}.
       
    49  *
    48  *
    50  * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
    49  * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
    51  * @see java.util.concurrent.locks.Condition
    50  * @see java.util.concurrent.locks.Condition
    52  *
    51  *
    53  * @author  Mandy Chung
    52  * @author  Mandy Chung
    64      *
    63      *
    65      * @param className the fully qualified name of the class of the lock object.
    64      * @param className the fully qualified name of the class of the lock object.
    66      * @param identityHashCode the {@link System#identityHashCode
    65      * @param identityHashCode the {@link System#identityHashCode
    67      *                         identity hash code} of the lock object.
    66      *                         identity hash code} of the lock object.
    68      */
    67      */
    69     @ConstructorProperties({"className", "identityHashCode"})
       
    70     public LockInfo(String className, int identityHashCode) {
    68     public LockInfo(String className, int identityHashCode) {
    71         if (className == null) {
    69         if (className == null) {
    72             throw new NullPointerException("Parameter className cannot be null");
    70             throw new NullPointerException("Parameter className cannot be null");
    73         }
    71         }
    74         this.className = className;
    72         this.className = className;
   101     public int getIdentityHashCode() {
    99     public int getIdentityHashCode() {
   102         return identityHashCode;
   100         return identityHashCode;
   103     }
   101     }
   104 
   102 
   105     /**
   103     /**
       
   104      * Returns a {@code LockInfo} object represented by the
       
   105      * given {@code CompositeData}.
       
   106      * The given {@code CompositeData} must contain the following attributes:
       
   107      * <blockquote>
       
   108      * <table border>
       
   109      * <tr>
       
   110      *   <th align=left>Attribute Name</th>
       
   111      *   <th align=left>Type</th>
       
   112      * </tr>
       
   113      * <tr>
       
   114      *   <td>className</td>
       
   115      *   <td><tt>java.lang.String</tt></td>
       
   116      * </tr>
       
   117      * <tr>
       
   118      *   <td>identityHashCode</td>
       
   119      *   <td><tt>java.lang.Integer</tt></td>
       
   120      * </tr>
       
   121      * </table>
       
   122      * </blockquote>
       
   123      *
       
   124      * @param cd {@code CompositeData} representing a {@code LockInfo}
       
   125      *
       
   126      * @throws IllegalArgumentException if {@code cd} does not
       
   127      *   represent a {@code LockInfo} with the attributes described
       
   128      *   above.
       
   129      * @return a {@code LockInfo} object represented
       
   130      *         by {@code cd} if {@code cd} is not {@code null};
       
   131      *         {@code null} otherwise.
       
   132      *
       
   133      * @since 1.8
       
   134      */
       
   135     public static LockInfo from(CompositeData cd) {
       
   136         if (cd == null) {
       
   137             return null;
       
   138         }
       
   139 
       
   140         if (cd instanceof LockInfoCompositeData) {
       
   141             return ((LockInfoCompositeData) cd).getLockInfo();
       
   142         } else {
       
   143             return LockInfoCompositeData.toLockInfo(cd);
       
   144         }
       
   145     }
       
   146 
       
   147     /**
   106      * Returns a string representation of a lock.  The returned
   148      * Returns a string representation of a lock.  The returned
   107      * string representation consists of the name of the class of the
   149      * string representation consists of the name of the class of the
   108      * lock object, the at-sign character `@', and the unsigned
   150      * lock object, the at-sign character `@', and the unsigned
   109      * hexadecimal representation of the <em>identity</em> hash code
   151      * hexadecimal representation of the <em>identity</em> hash code
   110      * of the object.  This method returns a string equals to the value of:
   152      * of the object.  This method returns a string equals to the value of: