/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* 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.
*/
"java.lang.management.ClassLoadingMXBean",
true, // singleton
new MXBeanFetcher<ClassLoadingMXBean>() {
}
}),
/**
* Compilation system of the Java virtual machine.
*/
"java.lang.management.CompilationMXBean",
true, // singleton
new MXBeanFetcher<CompilationMXBean>() {
if (m == null) {
return Collections.emptyList();
} else {
return Collections.singletonList(m);
}
}
}),
/**
* Memory system of the Java virtual machine.
*/
"java.lang.management.MemoryMXBean",
true, // singleton
new MXBeanFetcher<MemoryMXBean>() {
}
}),
/**
* Garbage Collector in the Java virtual machine.
*/
"java.lang.management.GarbageCollectorMXBean",
false, // zero or more instances
new MXBeanFetcher<GarbageCollectorMXBean>() {
return ManagementFactoryHelper.
}
}),
/**
* Memory manager in the Java virtual machine.
*/
"java.lang.management.MemoryManagerMXBean",
false, // zero or more instances
new MXBeanFetcher<MemoryManagerMXBean>() {
}
},
/**
* Memory pool in the Java virtual machine.
*/
"java.lang.management.MemoryPoolMXBean",
false, // zero or more instances
new MXBeanFetcher<MemoryPoolMXBean>() {
return ManagementFactoryHelper.getMemoryPoolMXBeans();
}
}),
/**
* Operating system on which the Java virtual machine is running
*/
"java.lang.management.OperatingSystemMXBean",
true, // singleton
new MXBeanFetcher<OperatingSystemMXBean>() {
}
}),
/**
* Runtime system of the Java virtual machine.
*/
"java.lang.management.RuntimeMXBean",
true, // singleton
new MXBeanFetcher<RuntimeMXBean>() {
}
}),
/**
* Threading system of the Java virtual machine.
*/
"java.lang.management.ThreadMXBean",
true, // singleton
new MXBeanFetcher<ThreadMXBean>() {
}
}),
/**
* Logging facility.
*/
"java.lang.management.PlatformLoggingMXBean",
true, // singleton
new MXBeanFetcher<PlatformLoggingMXBean>() {
if (m == null) {
return Collections.emptyList();
} else {
return Collections.singletonList(m);
}
}
}),
/**
* Buffer pools.
*/
"java.lang.management.BufferPoolMXBean",
false, // zero or more instances
new MXBeanFetcher<BufferPoolMXBean>() {
return ManagementFactoryHelper.getBufferPoolMXBeans();
}
}),
// Sun Platform Extension
/**
* Sun extension garbage collector that performs collections in cycles.
*/
"com.sun.management.GarbageCollectorMXBean",
false, // zero or more instances
}
}),
/**
* Sun extension operating system on which the Java virtual machine
* is running.
*/
"com.sun.management.OperatingSystemMXBean",
true, // singleton
}
}),
/**
* Unix operating system.
*/
"com.sun.management.UnixOperatingSystemMXBean",
true, // singleton
new MXBeanFetcher<UnixOperatingSystemMXBean>() {
}
}),
/**
* Diagnostic support for the HotSpot Virtual Machine.
*/
"com.sun.management.HotSpotDiagnosticMXBean",
true, // singleton
new MXBeanFetcher<HotSpotDiagnosticMXBean>() {
}
});
/**
* A task that returns the MXBeans for a component.
*/
}
/*
* Returns a list of the GC MXBeans of the given type.
*/
private static <T extends GarbageCollectorMXBean>
for (GarbageCollectorMXBean m : list) {
if (gcMXBeanIntf.isInstance(m)) {
}
}
return result;
}
/*
* Returns the OS mxbean instance of the given type.
*/
private static <T extends OperatingSystemMXBean>
if (osMXBeanIntf.isInstance(m)) {
} else {
return Collections.emptyList();
}
}
private final boolean singleton;
boolean singleton,
this.mxbeanInterfaceName = intfName;
this.keyProperties = keyProperties;
this.subComponents = subComponents;
}
if (defaultKeyProps == null) {
}
return defaultKeyProps;
}
}
return set;
}
boolean isSingleton() {
return singleton;
}
return mxbeanInterfaceName;
}
@SuppressWarnings("unchecked")
try {
// Lazy loading the MXBean interface only when it is needed
return (Class<? extends PlatformManagedObject>)
} catch (ClassNotFoundException x) {
throw new AssertionError(x);
}
}
@SuppressWarnings("unchecked")
<T extends PlatformManagedObject>
{
return fetcher.getMXBeans();
}
{
if (!singleton)
throw new IllegalArgumentException(mxbeanInterfaceName +
" can have zero or more than one instances");
}
<T extends PlatformManagedObject>
{
if (!singleton)
throw new IllegalArgumentException(mxbeanInterfaceName +
" can have zero or more than one instances");
// ObjectName of a singleton MXBean contains only domain and type
on,
}
<T extends PlatformManagedObject>
{
);
}
return result;
}
{
// if there are more than 1 key properties (i.e. other than "type")
domainAndType += ",*";
}
}
return set;
}
// a map from MXBean interface name to PlatformComponent
private static synchronized void ensureInitialized() {
// Use String as the key rather than Class<?> to avoid
// causing unnecessary class loading of management interface
}
}
}
}
static <T extends PlatformManagedObject>
{
return pc;
return null;
}
}