0N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.management;
0N/A
0N/Aimport java.lang.management.MonitorInfo;
0N/Aimport javax.management.openmbean.CompositeType;
0N/Aimport javax.management.openmbean.CompositeData;
0N/Aimport javax.management.openmbean.CompositeDataSupport;
0N/Aimport javax.management.openmbean.OpenDataException;
0N/Aimport java.util.Set;
0N/A
0N/A/**
0N/A * A CompositeData for MonitorInfo for the local management support.
0N/A * This class avoids the performance penalty paid to the
0N/A * construction of a CompositeData use in the local case.
0N/A */
0N/Apublic class MonitorInfoCompositeData extends LazyCompositeData {
0N/A private final MonitorInfo lock;
0N/A
0N/A private MonitorInfoCompositeData(MonitorInfo mi) {
0N/A this.lock = mi;
0N/A }
0N/A
0N/A public MonitorInfo getMonitorInfo() {
0N/A return lock;
0N/A }
0N/A
0N/A public static CompositeData toCompositeData(MonitorInfo mi) {
0N/A MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi);
0N/A return micd.getCompositeData();
0N/A }
0N/A
0N/A protected CompositeData getCompositeData() {
0N/A // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
0N/A // monitorInfoItemNames!
0N/A
0N/A int len = monitorInfoItemNames.length;
0N/A Object[] values = new Object[len];
0N/A CompositeData li = LockDataConverter.toLockInfoCompositeData(lock);
0N/A
0N/A for (int i = 0; i < len; i++) {
0N/A String item = monitorInfoItemNames[i];
0N/A if (item.equals(LOCKED_STACK_FRAME)) {
0N/A StackTraceElement ste = lock.getLockedStackFrame();
0N/A values[i] = (ste != null ? StackTraceElementCompositeData.
0N/A toCompositeData(ste)
0N/A : null);
0N/A } else if (item.equals(LOCKED_STACK_DEPTH)) {
0N/A values[i] = new Integer(lock.getLockedStackDepth());
0N/A } else {
0N/A values[i] = li.get(item);
0N/A }
0N/A }
0N/A
0N/A try {
0N/A return new CompositeDataSupport(monitorInfoCompositeType,
0N/A monitorInfoItemNames,
0N/A values);
0N/A } catch (OpenDataException e) {
0N/A // Should never reach here
178N/A throw new AssertionError(e);
0N/A }
0N/A }
0N/A
0N/A private static final CompositeType monitorInfoCompositeType;
0N/A private static final String[] monitorInfoItemNames;
0N/A static {
0N/A try {
0N/A monitorInfoCompositeType = (CompositeType)
0N/A MappedMXBeanType.toOpenType(MonitorInfo.class);
0N/A Set<String> s = monitorInfoCompositeType.keySet();
0N/A monitorInfoItemNames = (String[]) s.toArray(new String[0]);
0N/A } catch (OpenDataException e) {
0N/A // Should never reach here
178N/A throw new AssertionError(e);
0N/A }
0N/A }
0N/A
0N/A static CompositeType getMonitorInfoCompositeType() {
0N/A return monitorInfoCompositeType;
0N/A }
0N/A
0N/A private static final String CLASS_NAME = "className";
0N/A private static final String IDENTITY_HASH_CODE = "identityHashCode";
0N/A private static final String LOCKED_STACK_FRAME = "lockedStackFrame";
0N/A private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";
0N/A
0N/A public static String getClassName(CompositeData cd) {
0N/A return getString(cd, CLASS_NAME);
0N/A }
0N/A
0N/A public static int getIdentityHashCode(CompositeData cd) {
0N/A return getInt(cd, IDENTITY_HASH_CODE);
0N/A }
0N/A
0N/A public static StackTraceElement getLockedStackFrame(CompositeData cd) {
0N/A CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
0N/A if (ste != null) {
0N/A return StackTraceElementCompositeData.from(ste);
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A public static int getLockedStackDepth(CompositeData cd) {
0N/A return getInt(cd, LOCKED_STACK_DEPTH);
0N/A }
0N/A
0N/A /** Validate if the input CompositeData has the expected
0N/A * CompositeType (i.e. contain all attributes with expected
0N/A * names and types).
0N/A */
0N/A public static void validateCompositeData(CompositeData cd) {
0N/A if (cd == null) {
0N/A throw new NullPointerException("Null CompositeData");
0N/A }
0N/A
0N/A if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) {
0N/A throw new IllegalArgumentException(
0N/A "Unexpected composite type for MonitorInfo");
0N/A }
0N/A }
1807N/A
1807N/A private static final long serialVersionUID = -5825215591822908529L;
0N/A}