0N/A/*
2362N/A * Copyright (c) 2004, 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.MemoryUsage;
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/A
0N/A/**
0N/A * A CompositeData for MemoryUsage 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 MemoryUsageCompositeData extends LazyCompositeData {
0N/A private final MemoryUsage usage;
0N/A
0N/A private MemoryUsageCompositeData(MemoryUsage u) {
0N/A this.usage = u;
0N/A }
0N/A
0N/A public MemoryUsage getMemoryUsage() {
0N/A return usage;
0N/A }
0N/A
0N/A public static CompositeData toCompositeData(MemoryUsage u) {
0N/A MemoryUsageCompositeData mucd = new MemoryUsageCompositeData(u);
0N/A return mucd.getCompositeData();
0N/A }
0N/A
0N/A protected CompositeData getCompositeData() {
0N/A // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
0N/A // memoryUsageItemNames!
0N/A final Object[] memoryUsageItemValues = {
0N/A new Long(usage.getInit()),
0N/A new Long(usage.getUsed()),
0N/A new Long(usage.getCommitted()),
0N/A new Long(usage.getMax()),
0N/A };
0N/A
0N/A try {
0N/A return new CompositeDataSupport(memoryUsageCompositeType,
0N/A memoryUsageItemNames,
0N/A memoryUsageItemValues);
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 memoryUsageCompositeType;
0N/A static {
0N/A try {
0N/A memoryUsageCompositeType = (CompositeType)
0N/A MappedMXBeanType.toOpenType(MemoryUsage.class);
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 getMemoryUsageCompositeType() {
0N/A return memoryUsageCompositeType;
0N/A }
0N/A
0N/A private static final String INIT = "init";
0N/A private static final String USED = "used";
0N/A private static final String COMMITTED = "committed";
0N/A private static final String MAX = "max";
0N/A
0N/A private static final String[] memoryUsageItemNames = {
0N/A INIT,
0N/A USED,
0N/A COMMITTED,
0N/A MAX,
0N/A };
0N/A
0N/A public static long getInit(CompositeData cd) {
0N/A return getLong(cd, INIT);
0N/A }
0N/A public static long getUsed(CompositeData cd) {
0N/A return getLong(cd, USED);
0N/A }
0N/A public static long getCommitted(CompositeData cd) {
0N/A return getLong(cd, COMMITTED);
0N/A }
0N/A public static long getMax(CompositeData cd) {
0N/A return getLong(cd, MAX);
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(memoryUsageCompositeType, cd.getCompositeType())) {
0N/A throw new IllegalArgumentException(
0N/A "Unexpected composite type for MemoryUsage");
0N/A }
0N/A }
1807N/A
1807N/A private static final long serialVersionUID = -8504291541083874143L;
0N/A}