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.MemoryNotificationInfo;
0N/Aimport java.lang.management.MemoryUsage;
0N/Aimport javax.management.openmbean.CompositeData;
0N/Aimport javax.management.openmbean.CompositeType;
0N/Aimport javax.management.openmbean.CompositeDataSupport;
0N/Aimport javax.management.openmbean.OpenDataException;
0N/A
0N/A/**
0N/A * A CompositeData for MemoryNotificationInfo 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 MemoryNotifInfoCompositeData extends LazyCompositeData {
0N/A private final MemoryNotificationInfo memoryNotifInfo;
0N/A
0N/A private MemoryNotifInfoCompositeData(MemoryNotificationInfo info) {
0N/A this.memoryNotifInfo = info;
0N/A }
0N/A
0N/A public MemoryNotificationInfo getMemoryNotifInfo() {
0N/A return memoryNotifInfo;
0N/A }
0N/A
0N/A public static CompositeData toCompositeData(MemoryNotificationInfo info) {
0N/A MemoryNotifInfoCompositeData mnicd =
0N/A new MemoryNotifInfoCompositeData(info);
0N/A return mnicd.getCompositeData();
0N/A }
0N/A
0N/A protected CompositeData getCompositeData() {
0N/A // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
0N/A // memoryNotifInfoItemNames!
0N/A final Object[] memoryNotifInfoItemValues = {
0N/A memoryNotifInfo.getPoolName(),
0N/A MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),
0N/A new Long(memoryNotifInfo.getCount()),
0N/A };
0N/A
0N/A try {
0N/A return new CompositeDataSupport(memoryNotifInfoCompositeType,
0N/A memoryNotifInfoItemNames,
0N/A memoryNotifInfoItemValues);
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 memoryNotifInfoCompositeType;
0N/A static {
0N/A try {
0N/A memoryNotifInfoCompositeType = (CompositeType)
0N/A MappedMXBeanType.toOpenType(MemoryNotificationInfo.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 private static final String POOL_NAME = "poolName";
0N/A private static final String USAGE = "usage";
0N/A private static final String COUNT = "count";
0N/A private static final String[] memoryNotifInfoItemNames = {
0N/A POOL_NAME,
0N/A USAGE,
0N/A COUNT,
0N/A };
0N/A
0N/A
0N/A public static String getPoolName(CompositeData cd) {
0N/A String poolname = getString(cd, POOL_NAME);
0N/A if (poolname == null) {
0N/A throw new IllegalArgumentException("Invalid composite data: " +
0N/A "Attribute " + POOL_NAME + " has null value");
0N/A }
0N/A return poolname;
0N/A }
0N/A
0N/A public static MemoryUsage getUsage(CompositeData cd) {
0N/A CompositeData usageData = (CompositeData) cd.get(USAGE);
0N/A return MemoryUsage.from(usageData);
0N/A }
0N/A
0N/A public static long getCount(CompositeData cd) {
0N/A return getLong(cd, COUNT);
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(memoryNotifInfoCompositeType, cd.getCompositeType())) {
0N/A throw new IllegalArgumentException(
0N/A "Unexpected composite type for MemoryNotificationInfo");
0N/A }
0N/A }
0N/A
1807N/A private static final long serialVersionUID = -1805123446483771291L;
0N/A}