Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java
38827 views
/*1* Copyright (c) 2004, 2008, 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.MemoryNotificationInfo;28import java.lang.management.MemoryUsage;29import javax.management.openmbean.CompositeData;30import javax.management.openmbean.CompositeType;31import javax.management.openmbean.CompositeDataSupport;32import javax.management.openmbean.OpenDataException;3334/**35* A CompositeData for MemoryNotificationInfo 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 MemoryNotifInfoCompositeData extends LazyCompositeData {40private final MemoryNotificationInfo memoryNotifInfo;4142private MemoryNotifInfoCompositeData(MemoryNotificationInfo info) {43this.memoryNotifInfo = info;44}4546public MemoryNotificationInfo getMemoryNotifInfo() {47return memoryNotifInfo;48}4950public static CompositeData toCompositeData(MemoryNotificationInfo info) {51MemoryNotifInfoCompositeData mnicd =52new MemoryNotifInfoCompositeData(info);53return mnicd.getCompositeData();54}5556protected CompositeData getCompositeData() {57// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH58// memoryNotifInfoItemNames!59final Object[] memoryNotifInfoItemValues = {60memoryNotifInfo.getPoolName(),61MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),62new Long(memoryNotifInfo.getCount()),63};6465try {66return new CompositeDataSupport(memoryNotifInfoCompositeType,67memoryNotifInfoItemNames,68memoryNotifInfoItemValues);69} catch (OpenDataException e) {70// Should never reach here71throw new AssertionError(e);72}73}7475private static final CompositeType memoryNotifInfoCompositeType;76static {77try {78memoryNotifInfoCompositeType = (CompositeType)79MappedMXBeanType.toOpenType(MemoryNotificationInfo.class);80} catch (OpenDataException e) {81// Should never reach here82throw new AssertionError(e);83}84}8586private static final String POOL_NAME = "poolName";87private static final String USAGE = "usage";88private static final String COUNT = "count";89private static final String[] memoryNotifInfoItemNames = {90POOL_NAME,91USAGE,92COUNT,93};949596public static String getPoolName(CompositeData cd) {97String poolname = getString(cd, POOL_NAME);98if (poolname == null) {99throw new IllegalArgumentException("Invalid composite data: " +100"Attribute " + POOL_NAME + " has null value");101}102return poolname;103}104105public static MemoryUsage getUsage(CompositeData cd) {106CompositeData usageData = (CompositeData) cd.get(USAGE);107return MemoryUsage.from(usageData);108}109110public static long getCount(CompositeData cd) {111return getLong(cd, COUNT);112}113114/** Validate if the input CompositeData has the expected115* CompositeType (i.e. contain all attributes with expected116* names and types).117*/118public static void validateCompositeData(CompositeData cd) {119if (cd == null) {120throw new NullPointerException("Null CompositeData");121}122123if (!isTypeMatched(memoryNotifInfoCompositeType, cd.getCompositeType())) {124throw new IllegalArgumentException(125"Unexpected composite type for MemoryNotificationInfo");126}127}128129private static final long serialVersionUID = -1805123446483771291L;130}131132133