jdk/src/share/classes/java/lang/management/package.html
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!--
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 by Sun in the LICENSE file that accompanied this code.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
<body bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
Provides the management interface for monitoring and management of the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
Java virtual machine as well as the operating system on which the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
Java virtual machine is running.  It allows both local and remote 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
monitoring and management of the running Java virtual machine.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
<h4>Platform MXBeans</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
This package defines the management interface of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
components:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
<table cellspacing=1 summary="Description of the MBeans">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
<th><p align="left">Management Interface</p></th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
<th><p align="left">Description</p></th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
<td> <tt>{@link java.lang.management.ClassLoadingMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
<td> Class loading system of the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
<td> <tt>{@link java.lang.management.CompilationMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
<td> Compilation system of the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
<td> <tt>{@link java.lang.management.MemoryMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
<td> Memory system of the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
<td> <tt>{@link java.lang.management.ThreadMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
<td> Threads system of the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
<td> <tt>{@link java.lang.management.RuntimeMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
<td> Runtime system of the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
<td> <tt>{@link java.lang.management.OperatingSystemMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
<td> Operating system on which the Java virtual machine is running.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
<td> <tt>{@link java.lang.management.GarbageCollectorMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
<td> Garbage collector in the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
<td> <tt>{@link java.lang.management.MemoryManagerMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
<td> Memory manager in the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
<tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
<td> <tt>{@link java.lang.management.MemoryPoolMXBean}</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
<td> Memory pool in the Java virtual machine.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
A platform MXBean is a <i>managed bean</i> that defines the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
interface for one component for the platform and is specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
<a href="ManagementFactory.html#MXBean">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
ManagementFactory</a> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
<p>An application can monitor the instrumentation of the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
Java virtual machine and manage certain characteristics in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
the following ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
<li><i>Direct access to an MXBean interface</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    <ol type="a">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    <li>Get the MXBean instance through the static factory method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        and access the MXBean interface locally of the running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        virtual machine.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    <li>Construct an MXBean proxy instance that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        forwards the method calls to a given 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        {@link javax.management.MBeanServer MBeanServer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         ManagementFactory.newPlatformMXBeanProxy}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         A proxy is typically constructed to remotely access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         an MXBean of another running virtual machine.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    </ol></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
<li><i>Indirect access via {@link javax.management.MBeanServer MBeanServer} 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
       interface</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    <ol type="a">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    <li>Go through the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        {@link java.lang.management.ManagementFactory#getPlatformMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        platform MBeanServer} to access MXBeans locally or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        a specific <tt>MBeanServerConnection</tt> to access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        MXBeans remotely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        The attributes and operations of an MXBean use only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        <em>JMX open types</em> which include basic data types, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        {@link javax.management.openmbean.CompositeData CompositeData},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        and {@link javax.management.openmbean.TabularData TabularData} 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        defined in {@link javax.management.openmbean.OpenType OpenType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
       </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    </ol></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
Below shows a few <a href="#examples">examples</a> of different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
ways to access MXBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
<h4>ManagementFactory</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
The {@link java.lang.management.ManagementFactory} class is the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
factory class for the Java platform.  This class provides a set of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
static factory methods to obtain the MXBeans for the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
to allow an application to access the MXBeans directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
<p>A <em>platform MBeanServer</em> can be accessed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 getPlatformMBeanServer} method.  On the first call to this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
it creates the platform MBeanServer and registers all platform MXBeans 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
including platform MXBeans defined in other packages such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
{@link java.util.logging.LoggingMXBean}.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
Each platform MXBean is registered with a unique name defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{@link java.lang.management.ManagementFactory ManagementFactory} class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
for constructing {@link javax.management.ObjectName ObjectName}. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
This is a single MBeanServer that can be shared by different managed 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
components running within the same Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
<h4>Interoperability</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
A management application and a platform MBeanServer of a running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
virtual machine can interoperate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
without requiring classes used by the platform MXBean interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
The data types being transmitted between the JMX connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
server and the connector client are JMX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
{@link javax.management.openmbean.OpenType open types} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
this allows interoperation across versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
<p>A data type used by the MXBean interfaces are mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
an open type when being accessed via MBeanServer interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
The data type mapping is specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
{@link java.lang.management.ManagementFactory ManagementFactory} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
<h4><a name="examples">Ways to Access MXBeans</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
There are three different ways to access the management interfaces. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
<ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
<li>Call the methods in the MXBean directly within the same 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
   RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   // Get the standard attribute "VmVendor"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
   String vendor = mxbean.getVmVendor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
<li>Go through a <tt>MBeanServerConnection</tt> connecting 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    to the <tt>platform MBeanServer</tt> of a running virtual machine.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
   MBeanServerConnection mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
   // Connect to a running JVM (or itself) and get MBeanServerConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
   // that has the JVM MXBeans registered in it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
       // Assuming the RuntimeMXBean has been registered in mbs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
       ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
       // Get standard attribute "VmVendor"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
       String vendor = (String) mbs.getAttribute(oname, "VmVendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
   } catch (....) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
       // Catch the exceptions thrown by ObjectName constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
       // and MBeanServer.getAttribute method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
       ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
<li>Use MXBean proxy.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
   MBeanServerConnection mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
   // Connect to a running JVM (or itself) and get MBeanServerConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
   // that has the JVM MBeans registered in it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
   // Get a MBean proxy for RuntimeMXBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
   RuntimeMXBean proxy = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
       ManagementFactory.newPlatformMXBeanProxy(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                                ManagementFactory.RUNTIME_MXBEAN_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                                RuntimeMXBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
   // Get standard attribute "VmVendor" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
   String vendor = proxy.getVmVendor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
</ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
<h4><a name="extension">Platform Extension</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
A Java virtual machine implementation may add its platform extension to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
the management interface by defining platform-dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
interfaces that extend the standard management interfaces to include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
platform-specific metrics and management operations.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
The static factory methods in the <tt>ManagementFactory</tt> class will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
return the MBeans with the platform extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
It is recommended to name the platform-specific attributes with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
a vendor-specific prefix such as the vendor's name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
avoid collisions of the attribute name between the future extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
to the standard management interface and the platform extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
If the future extension to the standard management interface defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
a new attribute for a management interface and the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
is happened to be same as some vendor-specific attribute's name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
the applications accessing that vendor-specific attribute would have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
to be modified to cope with versioning and compatibility issues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
<p>Below is an example showing how to access a platform-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
attribute from Sun's implementation of the <tt>RuntimeMXBean</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
1) Direct access to the Sun-specific MXBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
   com.sun.management.RuntimeMXBean mxbean = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
       (com.sun.management.RuntimeMXBean) ManagementFactory.getRuntimeMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
   // Get the standard attribute "VmVendor"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
   String vendor = mxbean.getVmVendor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
   // Get the platform-specific attribute "Bar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
   BarType bar = mxbean.getBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
2) Access the Sun-specific MXBean interface via <tt>MBeanServer</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
   MBeanServerConnection mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
   // Connect to a running JVM (or itself) and get MBeanServerConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
   // that has the JVM MXBeans registered in it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
   try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
       // Assuming the RuntimeMXBean has been registered in mbs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
       ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
       // Get standard attribute "VmVendor"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
       String vendor = (String) mbs.getAttribute(oname, "VmVendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
       // Check if this MXBean contains Sun's extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
       if (mbs.isInstanceOf(oname, "com.sun.management.RuntimeMXBean")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
           // Get platform-specific attribute "Bar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
           BarType bar = (String) mbs.getAttribute(oname, "Bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
   } catch (....) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
       // Catch the exceptions thrown by ObjectName constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
       // and MBeanServer methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
       ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
or method in any class or interface in this package will cause a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
java.lang.NullPointerException NullPointerException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
<p> The java.lang.management API is thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
@see <a href="../../../javax/management/package-summary.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     JMX Specification.</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
@author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
@since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
</html>