|
Java example source code file (PlatformComponent.java)
The PlatformComponent.java Java example source code/* * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.lang.management; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.HashSet; import java.util.HashMap; import java.util.Map; import java.util.Set; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.UnixOperatingSystemMXBean; import sun.management.ManagementFactoryHelper; import sun.management.Util; /** * This enum class defines the list of platform components * that provides monitoring and management support. * Each enum represents one MXBean interface. A MXBean * instance could implement one or more MXBean interfaces. * * For example, com.sun.management.GarbageCollectorMXBean * extends java.lang.management.GarbageCollectorMXBean * and there is one set of garbage collection MXBean instances, * each of which implements both c.s.m. and j.l.m. interfaces. * There are two separate enums GARBAGE_COLLECTOR * and SUN_GARBAGE_COLLECTOR so that ManagementFactory.getPlatformMXBeans(Class) * will return the list of MXBeans of the specified type. * * To add a new MXBean interface for the Java platform, * add a new enum constant and implement the MXBeanFetcher. */ enum PlatformComponent { /** * Class loading system of the Java virtual machine. */ CLASS_LOADING( "java.lang.management.ClassLoadingMXBean", "java.lang", "ClassLoading", defaultKeyProperties(), true, // singleton new MXBeanFetcher<ClassLoadingMXBean>() { public List<ClassLoadingMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getClassLoadingMXBean()); } }), /** * Compilation system of the Java virtual machine. */ COMPILATION( "java.lang.management.CompilationMXBean", "java.lang", "Compilation", defaultKeyProperties(), true, // singleton new MXBeanFetcher<CompilationMXBean>() { public List<CompilationMXBean> getMXBeans() { CompilationMXBean m = ManagementFactoryHelper.getCompilationMXBean(); if (m == null) { return Collections.emptyList(); } else { return Collections.singletonList(m); } } }), /** * Memory system of the Java virtual machine. */ MEMORY( "java.lang.management.MemoryMXBean", "java.lang", "Memory", defaultKeyProperties(), true, // singleton new MXBeanFetcher<MemoryMXBean>() { public List<MemoryMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getMemoryMXBean()); } }), /** * Garbage Collector in the Java virtual machine. */ GARBAGE_COLLECTOR( "java.lang.management.GarbageCollectorMXBean", "java.lang", "GarbageCollector", keyProperties("name"), false, // zero or more instances new MXBeanFetcher<GarbageCollectorMXBean>() { public List<GarbageCollectorMXBean> getMXBeans() { return ManagementFactoryHelper. getGarbageCollectorMXBeans(); } }), /** * Memory manager in the Java virtual machine. */ MEMORY_MANAGER( "java.lang.management.MemoryManagerMXBean", "java.lang", "MemoryManager", keyProperties("name"), false, // zero or more instances new MXBeanFetcher<MemoryManagerMXBean>() { public List<MemoryManagerMXBean> getMXBeans() { return ManagementFactoryHelper.getMemoryManagerMXBeans(); } }, GARBAGE_COLLECTOR), /** * Memory pool in the Java virtual machine. */ MEMORY_POOL( "java.lang.management.MemoryPoolMXBean", "java.lang", "MemoryPool", keyProperties("name"), false, // zero or more instances new MXBeanFetcher<MemoryPoolMXBean>() { public List<MemoryPoolMXBean> getMXBeans() { return ManagementFactoryHelper.getMemoryPoolMXBeans(); } }), /** * Operating system on which the Java virtual machine is running */ OPERATING_SYSTEM( "java.lang.management.OperatingSystemMXBean", "java.lang", "OperatingSystem", defaultKeyProperties(), true, // singleton new MXBeanFetcher<OperatingSystemMXBean>() { public List<OperatingSystemMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getOperatingSystemMXBean()); } }), /** * Runtime system of the Java virtual machine. */ RUNTIME( "java.lang.management.RuntimeMXBean", "java.lang", "Runtime", defaultKeyProperties(), true, // singleton new MXBeanFetcher<RuntimeMXBean>() { public List<RuntimeMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getRuntimeMXBean()); } }), /** * Threading system of the Java virtual machine. */ THREADING( "java.lang.management.ThreadMXBean", "java.lang", "Threading", defaultKeyProperties(), true, // singleton new MXBeanFetcher<ThreadMXBean>() { public List<ThreadMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getThreadMXBean()); } }), /** * Logging facility. */ LOGGING( "java.lang.management.PlatformLoggingMXBean", "java.util.logging", "Logging", defaultKeyProperties(), true, // singleton new MXBeanFetcher<PlatformLoggingMXBean>() { public List<PlatformLoggingMXBean> getMXBeans() { PlatformLoggingMXBean m = ManagementFactoryHelper.getPlatformLoggingMXBean(); if (m == null) { return Collections.emptyList(); } else { return Collections.singletonList(m); } } }), /** * Buffer pools. */ BUFFER_POOL( "java.lang.management.BufferPoolMXBean", "java.nio", "BufferPool", keyProperties("name"), false, // zero or more instances new MXBeanFetcher<BufferPoolMXBean>() { public List<BufferPoolMXBean> getMXBeans() { return ManagementFactoryHelper.getBufferPoolMXBeans(); } }), // Sun Platform Extension /** * Sun extension garbage collector that performs collections in cycles. */ SUN_GARBAGE_COLLECTOR( "com.sun.management.GarbageCollectorMXBean", "java.lang", "GarbageCollector", keyProperties("name"), false, // zero or more instances new MXBeanFetcher<com.sun.management.GarbageCollectorMXBean>() { public List<com.sun.management.GarbageCollectorMXBean> getMXBeans() { return getGcMXBeanList(com.sun.management.GarbageCollectorMXBean.class); } }), /** * Sun extension operating system on which the Java virtual machine * is running. */ SUN_OPERATING_SYSTEM( "com.sun.management.OperatingSystemMXBean", "java.lang", "OperatingSystem", defaultKeyProperties(), true, // singleton new MXBeanFetcher<com.sun.management.OperatingSystemMXBean>() { public List<com.sun.management.OperatingSystemMXBean> getMXBeans() { return getOSMXBeanList(com.sun.management.OperatingSystemMXBean.class); } }), /** * Unix operating system. */ SUN_UNIX_OPERATING_SYSTEM( "com.sun.management.UnixOperatingSystemMXBean", "java.lang", "OperatingSystem", defaultKeyProperties(), true, // singleton new MXBeanFetcher<UnixOperatingSystemMXBean>() { public List<UnixOperatingSystemMXBean> getMXBeans() { return getOSMXBeanList(com.sun.management.UnixOperatingSystemMXBean.class); } }), /** * Diagnostic support for the HotSpot Virtual Machine. */ HOTSPOT_DIAGNOSTIC( "com.sun.management.HotSpotDiagnosticMXBean", "com.sun.management", "HotSpotDiagnostic", defaultKeyProperties(), true, // singleton new MXBeanFetcher<HotSpotDiagnosticMXBean>() { public List<HotSpotDiagnosticMXBean> getMXBeans() { return Collections.singletonList(ManagementFactoryHelper.getDiagnosticMXBean()); } }); /** * A task that returns the MXBeans for a component. */ interface MXBeanFetcher<T extends PlatformManagedObject> { public List<T> getMXBeans(); } /* * Returns a list of the GC MXBeans of the given type. */ private static <T extends GarbageCollectorMXBean> List<T> getGcMXBeanList(Class Other Java examples (source code examples)Here is a short list of links related to this Java PlatformComponent.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.