Path: blob/master/src/java.management/share/classes/sun/management/LockInfoCompositeData.java
41152 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.management;2627import java.lang.management.LockInfo;28import java.util.Map;29import javax.management.openmbean.CompositeType;30import javax.management.openmbean.CompositeData;31import javax.management.openmbean.CompositeDataSupport;32import javax.management.openmbean.OpenDataException;3334/**35* A CompositeData for LockInfo for the local management support.36* This class avoids the performance penalty paid to the37* construction of a CompositeData use in the local case.38*/39public class LockInfoCompositeData extends LazyCompositeData {40@SuppressWarnings("serial") // Not statically typed as Serializable41private final LockInfo lock;4243private LockInfoCompositeData(LockInfo li) {44this.lock = li;45}4647public LockInfo getLockInfo() {48return lock;49}5051public static CompositeData toCompositeData(LockInfo li) {52if (li == null) {53return null;54}5556LockInfoCompositeData licd = new LockInfoCompositeData(li);57return licd.getCompositeData();58}5960protected CompositeData getCompositeData() {61Map<String,Object> items = Map.of(62CLASS_NAME, lock.getClassName(),63IDENTITY_HASH_CODE, lock.getIdentityHashCode()64);6566try {67return new CompositeDataSupport(LOCK_INFO_COMPOSITE_TYPE, items);68} catch (OpenDataException e) {69// Should never reach here70throw Util.newException(e);71}72}7374private static final CompositeType LOCK_INFO_COMPOSITE_TYPE;75static {76try {77LOCK_INFO_COMPOSITE_TYPE = (CompositeType)78MappedMXBeanType.toOpenType(LockInfo.class);79} catch (OpenDataException e) {80// Should never reach here81throw Util.newException(e);82}83}8485static CompositeType compositeType() {86return LOCK_INFO_COMPOSITE_TYPE;87}8889private static final String CLASS_NAME = "className";90private static final String IDENTITY_HASH_CODE = "identityHashCode";9192/*93* Returns a LockInfo object mapped from the given CompositeData.94*/95public static LockInfo toLockInfo(CompositeData cd) {96if (cd == null) {97throw new NullPointerException("Null CompositeData");98}99100if (!isTypeMatched(LOCK_INFO_COMPOSITE_TYPE, cd.getCompositeType())) {101throw new IllegalArgumentException(102"Unexpected composite type for LockInfo");103}104105String className = getString(cd, CLASS_NAME);106int identityHashCode = getInt(cd, IDENTITY_HASH_CODE);107return new LockInfo(className, identityHashCode);108}109110private static final long serialVersionUID = -6374759159749014052L;111}112113114