jdk/src/share/classes/java/lang/management/ManagementFactory.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7803 56bc97d69d93
child 9050 26c2c1de1631
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7803
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.management;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    27
import javax.management.DynamicMBean;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.MBeanServerConnection;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    30
import javax.management.MBeanServerFactory;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.MBeanServerPermission;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    32
import javax.management.NotificationEmitter;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    33
import javax.management.ObjectInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.ObjectName;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    35
import javax.management.InstanceAlreadyExistsException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MalformedObjectNameException;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    38
import javax.management.MBeanRegistrationException;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    39
import javax.management.NotCompliantMBeanException;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    40
import javax.management.StandardEmitterMBean;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    41
import javax.management.StandardMBean;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    42
import java.util.Collections;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    43
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.PrivilegedAction;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    48
import java.security.PrivilegedActionException;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    49
import java.security.PrivilegedExceptionAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.JMX;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    51
import sun.management.ManagementFactoryHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The <tt>ManagementFactory</tt> class is a factory class for getting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * managed beans for the Java platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This class consists of static methods each of which returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * one or more <a href="#MXBean">platform MXBean(s)</a> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the management interface of a component of the Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * An application can access a platform MXBean in the following ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <li><i>Direct access to an MXBean interface</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     <ol type="a">
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    66
 *     <li>Get the MXBean instance through the static factory method,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    67
 *         or the {@link #getPlatformMXBeans(Class)} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *         and access the MXBean locally of the running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *         virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *         </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *     <li>Construct an MXBean proxy instance that forwards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *         method calls to a given {@link MBeanServer MBeanServer} by calling
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    73
 *         the {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    74
 *         or the {@link #getPlatformMXBeans(MBeanServerConnection, Class)}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    75
 *         method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *         A proxy is typically constructed to remotely access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *         an MXBean of another running virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *         </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *     </ol></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <li><i>Indirect access to an MXBean interface via MBeanServer</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *     <ol type="a">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *     <li>Go through the {@link #getPlatformMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *         platform MBeanServer} to access MXBeans locally or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *         a specific <tt>MBeanServerConnection</tt> to access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *         MXBeans remotely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *         The attributes and operations of an MXBean use only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *         <em>JMX open types</em> which include basic data types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *         {@link javax.management.openmbean.CompositeData CompositeData},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *         and {@link javax.management.openmbean.TabularData TabularData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *         defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *         {@link javax.management.openmbean.OpenType OpenType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *         The mapping is specified below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *     </ol></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <h4><a name="MXBean">Platform MXBeans</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * A platform MXBean is a <i>managed bean</i> that conforms to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * the JMX Instrumentation Specification and only uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * a set of basic data types described below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * See <a href="../../../javax/management/MXBean.html#MXBean-spec">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * the specification of MXBeans</a> for details.
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   103
 * All platform MXBean interfaces extend {@link PlatformManagedObject}s
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   104
 * and new methods may be added in these interfaces
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   105
 * in future Java SE releases.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   106
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * A JMX management application and the platform <tt>MBeanServer</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * can interoperate without requiring classes for MXBean specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * data types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * The data types being transmitted between the JMX connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * server and the connector client are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * {@linkplain javax.management.openmbean.OpenType open types}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * and this allows interoperation across versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * The platform MXBean interfaces use only the following data types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *   <li>Primitive types such as <tt>int</tt>, <tt>long</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *       <tt>boolean</tt>, etc</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *   <li>Wrapper classes for primitive types such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *       {@link java.lang.Integer Integer}, {@link java.lang.Long Long},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *       {@link java.lang.Boolean Boolean}, etc and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *       {@link java.lang.String String}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *   <li>{@link java.lang.Enum Enum} classes</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *   <li>Classes that define only getter methods and define a static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *       <tt>from</tt> method with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *       {@link javax.management.openmbean.CompositeData CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *       argument to convert from an input <tt>CompositeData</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *       an instance of that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *   <li>{@link java.util.List List&lt;E&gt;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *       where <tt>E</tt> is a primitive type, a wrapper class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *       an enum class, or a class supporting conversion from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *       <tt>CompositeData</tt> to its class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *   <li>{@link java.util.Map Map&lt;K,V&gt;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *       where <tt>K</tt> and <tt>V</tt> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *       a primitive type, a wrapper class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *       an enum class, or a class supporting conversion from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *       <tt>CompositeData</tt> to its class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * When an attribute or operation of a platform MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * is accessed via an <tt>MBeanServer</tt>, the data types are mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *   <li>A primitive type or a wrapper class is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *       to the same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *   <li>An {@link Enum} is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *       <tt>String</tt> whose value is the name of the enum constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *   <li>A class that defines only getter methods and a static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *       <tt>from</tt> method with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *       {@link javax.management.openmbean.CompositeData CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *       argument is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *       {@link javax.management.openmbean.CompositeData CompositeData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *   <li><tt>Map&lt;K,V&gt;</tt> is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *       {@link javax.management.openmbean.TabularData TabularData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *       whose row type is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *       {@link javax.management.openmbean.CompositeType CompositeType} with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *       two items whose names are <i>"key"</i> and <i>"value"</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *       and the item types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *       the corresponding mapped type of <tt>K</tt> and <tt>V</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *       respectively and the <i>"key"</i> is the index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *   <li><tt>List&lt;E&gt;</tt> is mapped to an array with the mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *       type of <tt>E</tt> as the element type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *   <li>An array of element type <tt>E</tt> is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *       an array of the same dimenions with the mapped type of <tt>E</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *       as the element type.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * The {@link javax.management.MBeanInfo MBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * for a platform MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * describes the data types of the attributes and operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * as primitive or open types mapped as specified above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * For example, the {@link MemoryMXBean}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * interface has the following <i>getter</i> and <i>setter</i> methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * public MemoryUsage getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * public boolean isVerbose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * public void setVerbose(boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * These attributes in the <tt>MBeanInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * of the <tt>MemoryMXBean</tt> have the following names and types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * <table border>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *   <th>Attribute Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *   <th>Type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *   </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 *   <td><tt>HeapMemoryUsage</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *   <td>{@link MemoryUsage#from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *              CompositeData representing MemoryUsage}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *   <td><tt>Verbose</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *   <td><tt>boolean</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * <h4><a name="MXBeanNames">MXBean Names</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * Each platform MXBean for a Java virtual machine has a unique
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * {@link javax.management.ObjectName ObjectName} for
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   215
 * registration in the platform <tt>MBeanServer</tt> that can
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   216
 * be obtained by calling the {@link PlatformManagedObject#getObjectName}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   217
 * method.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   218
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * A Java virtual machine has a single instance of the following management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * interfaces:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * <table border>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * <th>Management Interface</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * <th>ObjectName</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * <td> {@link ClassLoadingMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * <td> {@link #CLASS_LOADING_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *             <tt>java.lang:type=ClassLoading</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * <td> {@link MemoryMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * <td> {@link #MEMORY_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *             <tt>java.lang:type=Memory</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * <td> {@link ThreadMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * <td> {@link #THREAD_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *             <tt>java.lang:type=Threading</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * <td> {@link RuntimeMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * <td> {@link #RUNTIME_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *             <tt>java.lang:type=Runtime</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * <td> {@link OperatingSystemMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * <td> {@link #OPERATING_SYSTEM_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *             <tt>java.lang:type=OperatingSystem</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * A Java virtual machine has zero or a single instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * the following management interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * <table border>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * <th>Management Interface</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * <th>ObjectName</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * <td> {@link CompilationMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <td> {@link #COMPILATION_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *             <tt>java.lang:type=Compilation</tt>}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * A Java virtual machine may have one or more instances of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * management interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * <table border>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * <th>Management Interface</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * <th>ObjectName</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * <td> {@link GarbageCollectorMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *    <tt>java.lang:type=GarbageCollector</tt>}<tt>,name=</tt><i>collector's name</i></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * <td> {@link MemoryManagerMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *    <tt>java.lang:type=MemoryManager</tt>}<tt>,name=</tt><i>manager's name</i></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * <td> {@link MemoryPoolMXBean} </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 *    <tt>java.lang:type=MemoryPool</tt>}<tt>,name=</tt><i>pool's name</i></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * @see <a href="../../../javax/management/package-summary.html">
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   302
 *      JMX Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * @see <a href="package-summary.html#examples">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *      Ways to Access Management Metrics</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * @see java.util.logging.LoggingMXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * @see javax.management.MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
public class ManagementFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    // A class with only static fields and methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    private ManagementFactory() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <tt>ObjectName</tt> for the {@link ClassLoadingMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public final static String CLASS_LOADING_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        "java.lang:type=ClassLoading";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <tt>ObjectName</tt> for the {@link CompilationMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public final static String COMPILATION_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        "java.lang:type=Compilation";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <tt>ObjectName</tt> for the {@link MemoryMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public final static String MEMORY_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        "java.lang:type=Memory";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <tt>ObjectName</tt> for the {@link OperatingSystemMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public final static String OPERATING_SYSTEM_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        "java.lang:type=OperatingSystem";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <tt>ObjectName</tt> for the {@link RuntimeMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public final static String RUNTIME_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        "java.lang:type=Runtime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <tt>ObjectName</tt> for the {@link ThreadMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public final static String THREAD_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        "java.lang:type=Threading";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The domain name and the type key property in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * the <tt>ObjectName</tt> for a {@link GarbageCollectorMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * The unique <tt>ObjectName</tt> for a <tt>GarbageCollectorMXBean</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * can be formed by appending this string with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * "<tt>,name=</tt><i>collector's name</i>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public final static String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        "java.lang:type=GarbageCollector";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * The domain name and the type key property in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * the <tt>ObjectName</tt> for a {@link MemoryManagerMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * The unique <tt>ObjectName</tt> for a <tt>MemoryManagerMXBean</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * can be formed by appending this string with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * "<tt>,name=</tt><i>manager's name</i>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public final static String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        "java.lang:type=MemoryManager";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * The domain name and the type key property in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * the <tt>ObjectName</tt> for a {@link MemoryPoolMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * The unique <tt>ObjectName</tt> for a <tt>MemoryPoolMXBean</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * can be formed by appending this string with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <tt>,name=</tt><i>pool's name</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public final static String MEMORY_POOL_MXBEAN_DOMAIN_TYPE=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        "java.lang:type=MemoryPool";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns the managed bean for the class loading system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return a {@link ClassLoadingMXBean} object for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public static ClassLoadingMXBean getClassLoadingMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   395
        return ManagementFactoryHelper.getClassLoadingMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Returns the managed bean for the memory system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return a {@link MemoryMXBean} object for the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public static MemoryMXBean getMemoryMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   405
        return ManagementFactoryHelper.getMemoryMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Returns the managed bean for the thread system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @return a {@link ThreadMXBean} object for the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public static ThreadMXBean getThreadMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   415
        return ManagementFactoryHelper.getThreadMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Returns the managed bean for the runtime system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @return a {@link RuntimeMXBean} object for the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public static RuntimeMXBean getRuntimeMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   426
        return ManagementFactoryHelper.getRuntimeMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Returns the managed bean for the compilation system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * the Java virtual machine.  This method returns <tt>null</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * if the Java virtual machine has no compilation system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @return a {@link CompilationMXBean} object for the Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *   machine or <tt>null</tt> if the Java virtual machine has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *   no compilation system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public static CompilationMXBean getCompilationMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   439
        return ManagementFactoryHelper.getCompilationMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Returns the managed bean for the operating system on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * the Java virtual machine is running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @return an {@link OperatingSystemMXBean} object for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public static OperatingSystemMXBean getOperatingSystemMXBean() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   450
        return ManagementFactoryHelper.getOperatingSystemMXBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Returns a list of {@link MemoryPoolMXBean} objects in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * The Java virtual machine can have one or more memory pools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * It may add or remove memory pools during execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @return a list of <tt>MemoryPoolMXBean</tt> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   463
        return ManagementFactoryHelper.getMemoryPoolMXBeans();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Returns a list of {@link MemoryManagerMXBean} objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * in the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * The Java virtual machine can have one or more memory managers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * It may add or remove memory managers during execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @return a list of <tt>MemoryManagerMXBean</tt> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   476
        return ManagementFactoryHelper.getMemoryManagerMXBeans();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Returns a list of {@link GarbageCollectorMXBean} objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * in the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * The Java virtual machine may have one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <tt>GarbageCollectorMXBean</tt> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * It may add or remove <tt>GarbageCollectorMXBean</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * during execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return a list of <tt>GarbageCollectorMXBean</tt> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   492
        return ManagementFactoryHelper.getGarbageCollectorMXBeans();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    private static MBeanServer platformMBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Returns the platform {@link javax.management.MBeanServer MBeanServer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * On the first call to this method, it first creates the platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * <tt>MBeanServer</tt> by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * {@link javax.management.MBeanServerFactory#createMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * MBeanServerFactory.createMBeanServer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * method and registers the platform MXBeans in this platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * <tt>MBeanServer</tt> using the <a href="#MXBeanNames">MXBean names</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * defined in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * This method, in subsequent calls, will simply return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * initially created platform <tt>MBeanServer</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * MXBeans that get created and destroyed dynamically, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * memory {@link MemoryPoolMXBean pools} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * {@link MemoryManagerMXBean managers},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * will automatically be registered and deregistered into the platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <tt>MBeanServer</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * If the system property <tt>javax.management.builder.initial</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * is set, the platform <tt>MBeanServer</tt> creation will be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * by the specified {@link javax.management.MBeanServerBuilder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * It is recommended that this platform MBeanServer also be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * to register other application managed beans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * besides the platform MXBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * This will allow all MBeans to be published through the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <tt>MBeanServer</tt> and hence allow for easier network publishing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * and discovery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Name conflicts with the platform MXBeans should be avoided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @return the platform <tt>MBeanServer</tt>; the platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *         MXBeans are registered into the platform <tt>MBeanServer</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *         at the first time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @exception SecurityException if there is a security manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * and the caller does not have the permission required by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * {@link javax.management.MBeanServerFactory#createMBeanServer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see javax.management.MBeanServerFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @see javax.management.MBeanServerFactory#createMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public static synchronized MBeanServer getPlatformMBeanServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            Permission perm = new MBeanServerPermission("createMBeanServer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            sm.checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (platformMBeanServer == null) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   545
            platformMBeanServer = MBeanServerFactory.createMBeanServer();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   546
            for (PlatformComponent pc : PlatformComponent.values()) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   547
                List<? extends PlatformManagedObject> list =
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   548
                    pc.getMXBeans(pc.getMXBeanInterface());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   549
                for (PlatformManagedObject o : list) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   550
                    // Each PlatformComponent represents one management
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   551
                    // interface. Some MXBean may extend another one.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   552
                    // The MXBean instances for one platform component
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   553
                    // (returned by pc.getMXBeans()) might be also
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   554
                    // the MXBean instances for another platform component.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   555
                    // e.g. com.sun.management.GarbageCollectorMXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   556
                    //
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   557
                    // So need to check if an MXBean instance is registered
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   558
                    // before registering into the platform MBeanServer
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   559
                    if (!platformMBeanServer.isRegistered(o.getObjectName())) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   560
                        addMXBean(platformMBeanServer, o);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   561
                    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   562
                }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   563
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return platformMBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Returns a proxy for a platform MXBean interface of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * given <a href="#MXBeanNames">MXBean name</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * that forwards its method calls through the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * <tt>MBeanServerConnection</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <p>This method is equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * {@link java.lang.reflect.Proxy#newProxyInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *        Proxy.newProxyInstance}<tt>(mxbeanInterface.getClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *        new Class[] { mxbeanInterface }, handler)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * where <tt>handler</tt> is an {@link java.lang.reflect.InvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * InvocationHandler} to which method invocations to the MXBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * are dispatched. This <tt>handler</tt> converts an input parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * from an MXBean data type to its mapped open type before forwarding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * to the <tt>MBeanServer</tt> and converts a return value from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * an MXBean method call through the <tt>MBeanServer</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * from an open type to the corresponding return type declared in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * the MXBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * If the MXBean is a notification emitter (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * it implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * {@link javax.management.NotificationEmitter NotificationEmitter}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * both the <tt>mxbeanInterface</tt> and <tt>NotificationEmitter</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * will be implemented by this proxy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <b>Notes:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <li>Using an MXBean proxy is a convenience remote access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * a platform MXBean of a running virtual machine.  All method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * calls to the MXBean proxy are forwarded to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <tt>MBeanServerConnection</tt> where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * {@link java.io.IOException IOException} may be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * when the communication problem occurs with the connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * An application remotely accesses the platform MXBeans using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * proxy should prepare to catch <tt>IOException</tt> as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * accessing with the <tt>MBeanServerConnector</tt> interface.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <li>When a client application is designed to remotely access MXBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * for a running virtual machine whose version is different than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * the version on which the application is running,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * it should prepare to catch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * {@link java.io.InvalidObjectException InvalidObjectException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * which is thrown when an MXBean proxy receives a name of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * enum constant which is missing in the enum class loaded in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * the client application. </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <li>{@link javax.management.MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * MBeanServerInvocationHandler} or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * {@link javax.management.MBeanServerInvocationHandler#newProxyInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * newProxyInstance} method cannot be used to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * a proxy for a platform MXBean. The proxy object created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * by <tt>MBeanServerInvocationHandler</tt> does not handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * the properties of the platform MXBeans described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * the <a href="#MXBean">class specification</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @param connection the <tt>MBeanServerConnection</tt> to forward to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param mxbeanName the name of a platform MXBean within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * <tt>connection</tt> to forward to. <tt>mxbeanName</tt> must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * in the format of {@link ObjectName ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @param mxbeanInterface the MXBean interface to be implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * by the proxy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <li><tt>mxbeanName</tt> is not with a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *     {@link ObjectName ObjectName} format, or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <li>the named MXBean in the <tt>connection</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *     not a MXBean provided by the platform, or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <li>the named MXBean is not registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *     <tt>MBeanServerConnection</tt>, or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * <li>the named MXBean is not an instance of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *     <tt>mxbeanInterface</tt></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @throws java.io.IOException if a communication problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * occurred when accessing the <tt>MBeanServerConnection</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public static <T> T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        newPlatformMXBeanProxy(MBeanServerConnection connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                               String mxbeanName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                               Class<T> mxbeanInterface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        final Class interfaceClass = mxbeanInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // Only allow MXBean interfaces from rt.jar loaded by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        // bootstrap class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        final ClassLoader loader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                public ClassLoader run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    return interfaceClass.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if (loader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            throw new IllegalArgumentException(mxbeanName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                " is not a platform MXBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            final ObjectName objName = new ObjectName(mxbeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if (!connection.isInstanceOf(objName, interfaceClass.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                throw new IllegalArgumentException(mxbeanName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    " is not an instance of " + interfaceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            final Class[] interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            // check if the registered MBean is a notification emitter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            boolean emitter = connection.isInstanceOf(objName, NOTIF_EMITTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            // create an MXBean proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return JMX.newMXBeanProxy(connection, objName, mxbeanInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                      emitter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        } catch (InstanceNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            final IllegalArgumentException iae =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                new IllegalArgumentException(mxbeanName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    " not found in the connection.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        } catch (MalformedObjectNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            final IllegalArgumentException iae =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                new IllegalArgumentException(mxbeanName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    " is not a valid ObjectName format.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   701
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   702
     * Returns the list of platform MXBeans that implement
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   703
     * the given {@code mxbeanInterface} in the running Java
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   704
     * virtual machine.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   705
     * The returned list may contain zero, one, or more instances.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   706
     * The number of instances in the returned list is defined
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   707
     * in the specification of the given management interface.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   708
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   709
     * @param mxbeanInterface a management interface for a platform
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   710
     *                        MXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   711
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   712
     * @return the list of platform MXBeans that implements
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   713
     * {@code mxbeanInterface}.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   714
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   715
     * @throws IllegalArgumentException if {@code mxbeanInterface}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   716
     * is not a management interface for the platform.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   717
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   718
     * @since 1.7
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   719
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   720
    public static <T extends PlatformManagedObject> List<T>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   721
            getPlatformMXBeans(Class<T> mxbeanInterface) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   722
        String className = mxbeanInterface.getName();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   723
        for (PlatformComponent component: PlatformComponent.values()) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   724
            // comparing the class name first instead of the Class instance
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   725
            // to avoid causing unnecessary class loading of
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   726
            // the other MXBean interfaces
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   727
            if (className.equals(component.getMXBeanInterfaceName())) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   728
                if (component.getMXBeanInterface() == mxbeanInterface) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   729
                    return component.getMXBeans(mxbeanInterface);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   730
                }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   731
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   732
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   733
        throw new IllegalArgumentException(mxbeanInterface.getName() +
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   734
            " is not implemented by any of the platform MXBeans.");
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   735
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   736
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   737
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   738
     * Returns the list of the platform MXBean proxies for
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   739
     * forwarding the method calls of the {@code mxbeanInterface}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   740
     * through the given {@code MBeanServerConnection}.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   741
     * The returned list may contain zero, one, or more instances.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   742
     * The number of instances in the returned list is defined
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   743
     * in the specification of the given management interface.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   744
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   745
     * @param connection the {@code MBeanServerConnection} to forward to.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   746
     * @param mxbeanInterface a management interface for a platform
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   747
     *                        MXBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   748
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   749
     * @return the list of platform MXBean proxies for
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   750
     * forwarding the method calls of the {@code mxbeanInterface}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   751
     * through the given {@code MBeanServerConnection}.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   752
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   753
     * @throws IllegalArgumentException if {@code mxbeanInterface}
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   754
     * is not a management interface for the platform.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   755
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   756
     * @throws java.io.IOException if a communication problem
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   757
     * occurred when accessing the {@code MBeanServerConnection}.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   758
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   759
     * @since 1.7
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   760
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   761
    public static <T extends PlatformManagedObject>
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   762
        List<T> getPlatformMXBeans(MBeanServerConnection connection,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   763
                                   Class<T> mxbeanInterface)
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   764
        throws java.io.IOException
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   765
    {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   766
        String className = mxbeanInterface.getName();
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   767
        for (PlatformComponent component: PlatformComponent.values()) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   768
            // comparing the class name first instead of the Class instance
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   769
            // to avoid causing unnecessary class loading of
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   770
            // the other MXBean interfaces
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   771
            if (className.equals(component.getMXBeanInterfaceName())) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   772
                if (component.getMXBeanInterface() == mxbeanInterface) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   773
                    return component.getMXBeans(connection,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   774
                                                mxbeanInterface);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   775
                }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   776
            }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   777
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   778
        throw new IllegalArgumentException(mxbeanInterface.getName() +
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   779
            " is not implemented by any of the platform MXBeans.");
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   780
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   781
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   782
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   783
     * Returns a list of {@code Class} objects, subinterface of
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   784
     * {@link PlatformManagedObject}, representing
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   785
     * all management interfaces for
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   786
     * monitoring and managing the Java platform.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   787
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   788
     * @return a list of {@code Class} objects, subinterface of
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   789
     * {@link PlatformManagedObject} representing
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   790
     * the management interfaces for
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   791
     * monitoring and managing the Java platform.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   792
     *
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   793
     * @since 1.7
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   794
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   795
    public static List<Class<? extends PlatformManagedObject>> getAllPlatformMXBeanInterfaces() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   796
        List<Class<? extends PlatformManagedObject>> result =
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
   797
            new ArrayList<>();
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   798
        for (PlatformComponent component: PlatformComponent.values()) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   799
            result.add(component.getMXBeanInterface());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   800
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   801
        return result;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   802
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   803
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    private static final String NOTIF_EMITTER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        "javax.management.NotificationEmitter";
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   806
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   807
    /**
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   808
     * Registers an MXBean.
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   809
     */
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   810
    private static void addMXBean(final MBeanServer mbs, final PlatformManagedObject pmo) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   811
        // Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   812
        final DynamicMBean dmbean;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   813
        if (pmo instanceof NotificationEmitter) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   814
            dmbean = new StandardEmitterMBean(pmo, null, true, (NotificationEmitter) pmo);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   815
        } else {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   816
            dmbean = new StandardMBean(pmo, null, true);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   817
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   818
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   819
        try {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   820
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   821
                public Void run() throws InstanceAlreadyExistsException,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   822
                                         MBeanRegistrationException,
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   823
                                         NotCompliantMBeanException {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   824
                    mbs.registerMBean(dmbean, pmo.getObjectName());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   825
                    return null;
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   826
                }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   827
            });
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   828
        } catch (PrivilegedActionException e) {
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   829
            throw new RuntimeException(e.getException());
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   830
        }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   831
    }
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   832
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
}