Showing the changes to java/pkg/java/lang/management/LockInfo.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,122 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. | |
| 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 | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 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 | + * | |
| 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. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package java.lang.management; | |
| 27 | + | |
| 28 | +import javax.management.openmbean.CompositeData; | |
| 29 | +import java.util.concurrent.locks.*; | |
| 30 | +import java.beans.ConstructorProperties; | |
| 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 | + * | |
| 45 | + * <h4><a name="MappedType">MXBean Mapping</a></h4> | |
| 46 | + * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData} | |
| 47 | + * as specified in the <a href="../../../javax/management/MXBean.html#mapping-rules"> | |
| 48 | + * type mapping rules</a> of {@linkplain javax.management.MXBean MXBeans}. | |
| 49 | + * | |
| 50 | + * @see java.util.concurrent.locks.AbstractOwnableSynchronizer | |
| 51 | + * @see java.util.concurrent.locks.Condition | |
| 52 | + * | |
| 53 | + * @author Mandy Chung | |
| 54 | + * @since 1.6 | |
| 55 | + */ | |
| 56 | + | |
| 57 | +public class LockInfo { | |
| 58 | + | |
| 59 | + private String className; | |
| 60 | + private int identityHashCode; | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Constructs a <tt>LockInfo</tt> object. | |
| 64 | + * | |
| 65 | + * @param className the fully qualified name of the class of the lock object. | |
| 66 | + * @param identityHashCode the {@link System#identityHashCode | |
| 67 | + * identity hash code} of the lock object. | |
| 68 | + */ | |
| 69 | + @ConstructorProperties({"className", "identityHashCode"}) | |
| 70 | + public LockInfo(String className, int identityHashCode) { | |
| 71 | + if (className == null) { | |
| 72 | + throw new NullPointerException("Parameter className cannot be null"); | |
| 73 | + } | |
| 74 | + this.className = className; | |
| 75 | + this.identityHashCode = identityHashCode; | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * package-private constructors | |
| 80 | + */ | |
| 81 | + LockInfo(Object lock) { | |
| 82 | + this.className = lock.getClass().getName(); | |
| 83 | + this.identityHashCode = System.identityHashCode(lock); | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Returns the fully qualified name of the class of the lock object. | |
| 88 | + * | |
| 89 | + * @return the fully qualified name of the class of the lock object. | |
| 90 | + */ | |
| 91 | + public String getClassName() { | |
| 92 | + return className; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Returns the identity hash code of the lock object | |
| 97 | + * returned from the {@link System#identityHashCode} method. | |
| 98 | + * | |
| 99 | + * @return the identity hash code of the lock object. | |
| 100 | + */ | |
| 101 | + public int getIdentityHashCode() { | |
| 102 | + return identityHashCode; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Returns a string representation of a lock. The returned | |
| 107 | + * string representation consists of the name of the class of the | |
| 108 | + * lock object, the at-sign character `@', and the unsigned | |
| 109 | + * hexadecimal representation of the <em>identity</em> hash code | |
| 110 | + * of the object. This method returns a string equals to the value of: | |
| 111 | + * <blockquote> | |
| 112 | + * <pre> | |
| 113 | + * lock.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(lock)) | |
| 114 | + * </pre></blockquote> | |
| 115 | + * where <tt>lock</tt> is the lock object. | |
| 116 | + * | |
| 117 | + * @return the string representation of a lock. | |
| 118 | + */ | |
| 119 | + public String toString() { | |
| 120 | + return className + '@' + Integer.toHexString(identityHashCode); | |
| 121 | + } | |
| 122 | +} | |