jdk/src/share/classes/java/lang/management/PlatformComponent.java
author mchung
Tue, 27 Oct 2009 16:32:23 -0700
changeset 4172 bceea7bc12b7
parent 4156 acaa49a2768a
child 5506 202f599c92aa
permissions -rw-r--r--
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging Summary: Added a new PlatformLoggingMXBean interface to extend PlatformManagedObject instead of LoggingMXBean Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     1
/*
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     4
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    10
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    15
 * accompanied this code).
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    16
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    20
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    23
 * have any questions.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    24
 */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    25
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    26
package java.lang.management;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    27
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    28
import java.util.ArrayList;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    29
import java.util.Collections;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    30
import java.util.List;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    31
import java.util.HashSet;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    32
import java.util.Set;
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents: 4156
diff changeset
    33
import java.util.logging.PlatformLoggingMXBean;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
    34
import java.nio.BufferPoolMXBean;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    35
import javax.management.MBeanServerConnection;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    36
import javax.management.ObjectName;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    37
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    38
import com.sun.management.HotSpotDiagnosticMXBean;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    39
import com.sun.management.UnixOperatingSystemMXBean;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    40
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    41
import sun.management.ManagementFactoryHelper;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 3066
diff changeset
    42
import sun.management.Util;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    43
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    44
/**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    45
 * This enum class defines the list of platform components
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    46
 * that provides monitoring and management support.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    47
 * Each enum represents one MXBean interface. A MXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    48
 * instance could implement one or more MXBean interfaces.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    49
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    50
 * For example, com.sun.management.GarbageCollectorMXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    51
 * extends java.lang.management.GarbageCollectorMXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    52
 * and there is one set of garbage collection MXBean instances,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    53
 * each of which implements both c.s.m. and j.l.m. interfaces.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    54
 * There are two separate enums GARBAGE_COLLECTOR
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    55
 * and SUN_GARBAGE_COLLECTOR so that ManagementFactory.getPlatformMXBeans(Class)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    56
 * will return the list of MXBeans of the specified type.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    57
 *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    58
 * To add a new MXBean interface for the Java platform,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    59
 * add a new enum constant and implement the MXBeanFetcher.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    60
 */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    61
enum PlatformComponent {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    62
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    63
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    64
     * Class loading system of the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    65
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    66
    CLASS_LOADING(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    67
        "java.lang.management.ClassLoadingMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    68
        "java.lang", "ClassLoading", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    69
        new MXBeanFetcher<ClassLoadingMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    70
            public List<ClassLoadingMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    71
                return Collections.singletonList(ManagementFactoryHelper.getClassLoadingMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    72
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    73
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    74
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    75
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    76
     * Compilation system of the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    77
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    78
    COMPILATION(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    79
        "java.lang.management.CompilationMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    80
        "java.lang", "Compilation", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    81
        new MXBeanFetcher<CompilationMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    82
            public List<CompilationMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    83
                CompilationMXBean m = ManagementFactoryHelper.getCompilationMXBean();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    84
                if (m == null) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    85
                   return Collections.emptyList();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    86
                } else {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    87
                   return Collections.singletonList(m);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    88
                }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    89
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    90
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    91
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    92
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    93
     * Memory system of the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    94
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    95
    MEMORY(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    96
        "java.lang.management.MemoryMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    97
        "java.lang", "Memory", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    98
        new MXBeanFetcher<MemoryMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
    99
            public List<MemoryMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   100
                return Collections.singletonList(ManagementFactoryHelper.getMemoryMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   101
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   102
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   103
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   104
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   105
     * Garbage Collector in the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   106
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   107
    GARBAGE_COLLECTOR(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   108
        "java.lang.management.GarbageCollectorMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   109
        "java.lang", "GarbageCollector", keyProperties("name"),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   110
        new MXBeanFetcher<GarbageCollectorMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   111
            public List<GarbageCollectorMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   112
                return ManagementFactoryHelper.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   113
                           getGarbageCollectorMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   114
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   115
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   116
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   117
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   118
     * Memory manager in the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   119
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   120
    MEMORY_MANAGER(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   121
        "java.lang.management.MemoryManagerMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   122
        "java.lang", "MemoryManager", keyProperties("name"),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   123
        new MXBeanFetcher<MemoryManagerMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   124
            public List<MemoryManagerMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   125
                return ManagementFactoryHelper.getMemoryManagerMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   126
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   127
        },
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   128
        GARBAGE_COLLECTOR),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   129
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   130
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   131
     * Memory pool in the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   132
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   133
    MEMORY_POOL(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   134
        "java.lang.management.MemoryPoolMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   135
        "java.lang", "MemoryPool", keyProperties("name"),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   136
        new MXBeanFetcher<MemoryPoolMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   137
            public List<MemoryPoolMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   138
                return ManagementFactoryHelper.getMemoryPoolMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   139
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   140
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   141
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   142
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   143
     * Operating system on which the Java virtual machine is running
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   144
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   145
    OPERATING_SYSTEM(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   146
        "java.lang.management.OperatingSystemMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   147
        "java.lang", "OperatingSystem", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   148
        new MXBeanFetcher<OperatingSystemMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   149
            public List<OperatingSystemMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   150
                return Collections.singletonList(ManagementFactoryHelper.getOperatingSystemMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   151
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   152
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   153
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   154
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   155
     * Runtime system of the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   156
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   157
    RUNTIME(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   158
        "java.lang.management.RuntimeMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   159
        "java.lang", "Runtime", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   160
        new MXBeanFetcher<RuntimeMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   161
            public List<RuntimeMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   162
                return Collections.singletonList(ManagementFactoryHelper.getRuntimeMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   163
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   164
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   165
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   166
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   167
     * Threading system of the Java virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   168
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   169
    THREADING(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   170
        "java.lang.management.ThreadMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   171
        "java.lang", "Threading", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   172
        new MXBeanFetcher<ThreadMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   173
            public List<ThreadMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   174
                return Collections.singletonList(ManagementFactoryHelper.getThreadMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   175
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   176
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   177
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   178
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   179
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   180
     * Logging facility.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   181
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   182
    LOGGING(
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents: 4156
diff changeset
   183
        "java.util.logging.PlatformLoggingMXBean",
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   184
        "java.util.logging", "Logging", defaultKeyProperties(),
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents: 4156
diff changeset
   185
        new MXBeanFetcher<PlatformLoggingMXBean>() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents: 4156
diff changeset
   186
            public List<PlatformLoggingMXBean> getMXBeans() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents: 4156
diff changeset
   187
                return ManagementFactoryHelper.getLoggingMXBean();
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   188
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   189
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   190
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   191
    /**
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   192
     * Buffer pools.
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   193
     */
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   194
    BUFFER_POOL(
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   195
        "java.nio.BufferPoolMXBean",
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   196
        "java.nio", "BufferPool", keyProperties("name"),
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   197
        new MXBeanFetcher<BufferPoolMXBean>() {
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   198
            public List<BufferPoolMXBean> getMXBeans() {
3066
cd3861104f4d 6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents: 1225
diff changeset
   199
                return ManagementFactoryHelper.getBufferPoolMXBeans();
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   200
            }
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   201
        }),
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   202
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 401
diff changeset
   203
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   204
    // Sun Platform Extension
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   205
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   206
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   207
     * Sun extension garbage collector that performs collections in cycles.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   208
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   209
    SUN_GARBAGE_COLLECTOR(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   210
        "com.sun.management.GarbageCollectorMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   211
        "java.lang", "GarbageCollector", keyProperties("name"),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   212
        new MXBeanFetcher<com.sun.management.GarbageCollectorMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   213
            public List<com.sun.management.GarbageCollectorMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   214
                return getGcMXBeanList(com.sun.management.GarbageCollectorMXBean.class);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   215
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   216
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   217
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   218
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   219
     * Sun extension operating system on which the Java virtual machine
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   220
     * is running.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   221
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   222
    SUN_OPERATING_SYSTEM(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   223
        "com.sun.management.OperatingSystemMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   224
        "java.lang", "OperatingSystem", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   225
        new MXBeanFetcher<com.sun.management.OperatingSystemMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   226
            public List<com.sun.management.OperatingSystemMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   227
                return getOSMXBeanList(com.sun.management.OperatingSystemMXBean.class);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   228
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   229
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   230
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   231
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   232
     * Unix operating system.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   233
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   234
    SUN_UNIX_OPERATING_SYSTEM(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   235
        "com.sun.management.UnixOperatingSystemMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   236
        "java.lang", "OperatingSystem", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   237
        new MXBeanFetcher<UnixOperatingSystemMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   238
            public List<UnixOperatingSystemMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   239
                return getOSMXBeanList(com.sun.management.UnixOperatingSystemMXBean.class);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   240
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   241
        }),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   242
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   243
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   244
     * Diagnostic support for the HotSpot Virtual Machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   245
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   246
    HOTSPOT_DIAGNOSTIC(
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   247
        "com.sun.management.HotSpotDiagnosticMXBean",
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   248
        "com.sun.management", "HotSpotDiagnostic", defaultKeyProperties(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   249
        new MXBeanFetcher<HotSpotDiagnosticMXBean>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   250
            public List<HotSpotDiagnosticMXBean> getMXBeans() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   251
                return Collections.singletonList(ManagementFactoryHelper.getDiagnosticMXBean());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   252
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   253
        });
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   254
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   255
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   256
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   257
     * A task that returns the MXBeans for a component.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   258
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   259
    interface MXBeanFetcher<T extends PlatformManagedObject> {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   260
        public List<T> getMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   261
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   262
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   263
    /*
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   264
     * Returns a list of the GC MXBeans of the given type.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   265
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   266
    private static <T extends GarbageCollectorMXBean>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   267
            List<T> getGcMXBeanList(Class<T> gcMXBeanIntf) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   268
        List<GarbageCollectorMXBean> list =
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   269
            ManagementFactoryHelper.getGarbageCollectorMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   270
        List<T> result = new ArrayList<T>(list.size());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   271
        for (GarbageCollectorMXBean m : list) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   272
            if (gcMXBeanIntf.isInstance(m)) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   273
                result.add(gcMXBeanIntf.cast(m));
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   274
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   275
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   276
        return result;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   277
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   278
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   279
    /*
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   280
     * Returns the OS mxbean instance of the given type.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   281
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   282
    private static <T extends OperatingSystemMXBean>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   283
            List<T> getOSMXBeanList(Class<T> osMXBeanIntf) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   284
        OperatingSystemMXBean m =
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   285
            ManagementFactoryHelper.getOperatingSystemMXBean();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   286
        if (osMXBeanIntf.isInstance(m)) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   287
            return Collections.singletonList(osMXBeanIntf.cast(m));
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   288
        } else {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   289
            return Collections.emptyList();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   290
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   291
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   292
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   293
    private final String mxbeanInterfaceName;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   294
    private final String domain;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   295
    private final String type;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   296
    private final Set<String> keyProperties;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   297
    private final MXBeanFetcher fetcher;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   298
    private final PlatformComponent[] subComponents;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   299
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   300
    private PlatformComponent(String intfName,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   301
                              String domain, String type,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   302
                              Set<String> keyProperties,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   303
                              MXBeanFetcher fetcher) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   304
        this.mxbeanInterfaceName = intfName;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   305
        this.domain = domain;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   306
        this.type = type;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   307
        this.keyProperties = keyProperties;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   308
        this.fetcher = fetcher;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   309
        this.subComponents = new PlatformComponent[0];
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   310
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   311
    private PlatformComponent(String intfName,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   312
                              String domain, String type,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   313
                              Set<String> keyProperties,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   314
                              MXBeanFetcher fetcher,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   315
                              PlatformComponent... subComponents) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   316
        this.mxbeanInterfaceName = intfName;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   317
        this.domain = domain;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   318
        this.type = type;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   319
        this.keyProperties = keyProperties;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   320
        this.fetcher = fetcher;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   321
        this.subComponents = subComponents;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   322
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   323
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   324
    private static Set<String> defaultKeyProps;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   325
    private static Set<String> defaultKeyProperties() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   326
        if (defaultKeyProps == null) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   327
            defaultKeyProps = Collections.singleton("type");
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   328
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   329
        return defaultKeyProps;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   330
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   331
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   332
    private static Set<String> keyProperties(String... keyNames) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   333
        Set<String> set = new HashSet<String>();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   334
        set.add("type");
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   335
        for (String s : keyNames) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   336
            set.add(s);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   337
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   338
        return set;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   339
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   340
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   341
    String getMXBeanInterfaceName() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   342
        return mxbeanInterfaceName;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   343
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   344
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   345
    @SuppressWarnings("unchecked")
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   346
    Class<? extends PlatformManagedObject> getMXBeanInterface() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   347
        try {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   348
            // Lazy loading the MXBean interface only when it is needed
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   349
            return (Class<? extends PlatformManagedObject>)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   350
                       Class.forName(mxbeanInterfaceName, false, null);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   351
        } catch (ClassNotFoundException x) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   352
            throw new AssertionError(x);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   353
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   354
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   355
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   356
    @SuppressWarnings("unchecked")
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   357
    <T extends PlatformManagedObject>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   358
        List<T> getMXBeans(Class<T> mxbeanInterface)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   359
    {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   360
        return fetcher.getMXBeans();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   361
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   362
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   363
    <T extends PlatformManagedObject>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   364
        List<T> getMXBeans(MBeanServerConnection mbs, Class<T> mxbeanInterface)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   365
        throws java.io.IOException
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   366
    {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   367
        List<T> result = new ArrayList<T>();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   368
        for (ObjectName on : getObjectNames(mbs)) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   369
            result.add(ManagementFactory.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   370
                newPlatformMXBeanProxy(mbs,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   371
                                       on.getCanonicalName(),
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   372
                                       mxbeanInterface)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   373
            );
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   374
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   375
        return result;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   376
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   377
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   378
    private Set<ObjectName> getObjectNames(MBeanServerConnection mbs)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   379
        throws java.io.IOException
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   380
    {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   381
        String domainAndType = domain + ":type=" + type;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   382
        if (keyProperties.size() > 1) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   383
            // if there are more than 1 key properties (i.e. other than "type")
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   384
            domainAndType += ",*";
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   385
        }
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 3066
diff changeset
   386
        ObjectName on = Util.newObjectName(domainAndType);
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   387
        Set<ObjectName> set =  mbs.queryNames(on, null);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   388
        for (PlatformComponent pc : subComponents) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   389
            set.addAll(pc.getObjectNames(mbs));
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   390
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   391
        return set;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   392
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   393
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   394
    private static final long serialVersionUID = 6992337162326171013L;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
diff changeset
   395
}