Path: blob/master/src/java.management/share/classes/sun/management/MemoryNotifInfoCompositeData.java
41152 views
/*1* Copyright (c) 2004, 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.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 {40@SuppressWarnings("serial") // Not statically typed as Serializable41private final MemoryNotificationInfo memoryNotifInfo;4243private MemoryNotifInfoCompositeData(MemoryNotificationInfo info) {44this.memoryNotifInfo = info;45}4647public MemoryNotificationInfo getMemoryNotifInfo() {48return memoryNotifInfo;49}5051public static CompositeData toCompositeData(MemoryNotificationInfo info) {52MemoryNotifInfoCompositeData mnicd =53new MemoryNotifInfoCompositeData(info);54return mnicd.getCompositeData();55}5657protected CompositeData getCompositeData() {58// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH59// memoryNotifInfoItemNames!60final Object[] memoryNotifInfoItemValues = {61memoryNotifInfo.getPoolName(),62MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),63memoryNotifInfo.getCount(),64};6566try {67return new CompositeDataSupport(memoryNotifInfoCompositeType,68memoryNotifInfoItemNames,69memoryNotifInfoItemValues);70} catch (OpenDataException e) {71// Should never reach here72throw new AssertionError(e);73}74}7576private static final CompositeType memoryNotifInfoCompositeType;77static {78try {79memoryNotifInfoCompositeType = (CompositeType)80MappedMXBeanType.toOpenType(MemoryNotificationInfo.class);81} catch (OpenDataException e) {82// Should never reach here83throw new AssertionError(e);84}85}8687private static final String POOL_NAME = "poolName";88private static final String USAGE = "usage";89private static final String COUNT = "count";90private static final String[] memoryNotifInfoItemNames = {91POOL_NAME,92USAGE,93COUNT,94};959697public static String getPoolName(CompositeData cd) {98String poolname = getString(cd, POOL_NAME);99if (poolname == null) {100throw new IllegalArgumentException("Invalid composite data: " +101"Attribute " + POOL_NAME + " has null value");102}103return poolname;104}105106public static MemoryUsage getUsage(CompositeData cd) {107CompositeData usageData = (CompositeData) cd.get(USAGE);108return MemoryUsage.from(usageData);109}110111public static long getCount(CompositeData cd) {112return getLong(cd, COUNT);113}114115/** Validate if the input CompositeData has the expected116* CompositeType (i.e. contain all attributes with expected117* names and types).118*/119public static void validateCompositeData(CompositeData cd) {120if (cd == null) {121throw new NullPointerException("Null CompositeData");122}123124if (!isTypeMatched(memoryNotifInfoCompositeType, cd.getCompositeType())) {125throw new IllegalArgumentException(126"Unexpected composite type for MemoryNotificationInfo");127}128}129130private static final long serialVersionUID = -1805123446483771291L;131}132133134