14 version 2 for more details (a copy is included in the LICENSE file that 15 accompanied this code). 16 17 You should have received a copy of the GNU General Public License version 18 2 along with this work; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 21 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 or visit www.oracle.com if you need additional information or have any 23 questions. 24 --> 25 26 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 27 <html> 28 <body bgcolor="white"> 29 30 Provides the management interfaces for monitoring and management of the 31 Java virtual machine and other components in the Java runtime. 32 It allows both local and remote 33 monitoring and management of the running Java virtual machine. 34 <p> 35 36 <h4><a name="MXBean">Platform MXBean</a></h4> 37 <p> 38 A platform MXBean is a <i>managed bean</i> that 39 conforms to the <a href="../../../javax/management/package-summary.html">JMX</a> 40 Instrumentation Specification and only uses a set of basic data types. 41 Each platform MXBean is a {@link java.lang.management.PlatformManagedObject} 42 with a unique 43 {@linkplain java.lang.management.PlatformManagedObject#getObjectName name}. 44 <p> 45 <h4>ManagementFactory</h4> 46 47 <p>The {@link java.lang.management.ManagementFactory} class is the management 48 factory class for the Java platform. This class provides a set of 49 static factory methods to obtain the MXBeans for the Java platform 50 to allow an application to access the MXBeans directly. 51 52 <p>A <em>platform MBeanServer</em> can be accessed with the 53 {@link java.lang.management.ManagementFactory#getPlatformMBeanServer 54 getPlatformMBeanServer} method. On the first call to this method, 55 it creates the platform MBeanServer and registers all platform MXBeans 56 including {@linkplain java.lang.management.PlatformManagedObject 57 platform MXBeans}. 58 Each platform MXBean is registered with a unique name defined in 59 the specification of the management interface. 60 This is a single MBeanServer that can be shared by different managed 61 components running within the same Java virtual machine. 62 63 <h4>Interoperability</h4> 64 65 <p>A management application and a platform MBeanServer of a running 66 virtual machine can interoperate 67 without requiring classes used by the platform MXBean interfaces. 68 The data types being transmitted between the JMX connector 69 server and the connector client are JMX 70 {@linkplain javax.management.openmbean.OpenType open types} and 71 this allows interoperation across versions. 72 A data type used by the MXBean interfaces are mapped to an 73 open type when being accessed via MBeanServer interface. 74 See the <a href="../../../javax/management/MXBean.html#MXBean-spec"> 75 MXBean</a> specification for details. 76 77 <h4><a name="examples">Ways to Access MXBeans</a></h4> 78 79 <p>An application can monitor the instrumentation of the 80 Java virtual machine and the runtime in the following ways: 81 <p> 82 <b>1. Direct access to an MXBean interface</b> 83 <p> 84 <ul> 85 <li>Get an MXBean instance locally in the running Java virtual machine: 86 <pre> 87 RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean(); 88 89 // Get the standard attribute "VmVendor" 90 String vendor = mxbean.getVmVendor(); 91 </pre> 92 <p>Or by calling the 93 {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class) 94 getPlatformMXBean} or 95 {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class) 96 getPlatformMXBeans} method: 97 <pre> 98 RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); 99 100 // Get the standard attribute "VmVendor" 101 String vendor = mxbean.getVmVendor(); 102 </pre> 103 <p> 104 </li> 105 <li>Construct an MXBean proxy instance that forwards the 106 method calls to a given MBeanServer: 107 <pre> 108 MBeanServerConnection mbs; 109 110 // Connect to a running JVM (or itself) and get MBeanServerConnection 111 // that has the JVM MBeans registered in it 112 ... 113 114 // Get a MBean proxy for RuntimeMXBean interface 115 RuntimeMXBean proxy = 116 {@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class) 117 ManagementFactory.getPlatformMXBean}(mbs, 118 RuntimeMXBean.class); 119 // Get standard attribute "VmVendor" 120 String vendor = proxy.getVmVendor(); 121 </pre> 122 <p>A proxy is typically used to access an MXBean 123 in a remote Java virtual machine. 124 An alternative way to create an MXBean proxy is: 125 <pre> 126 RuntimeMXBean proxy = 127 {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy 128 ManagementFactory.newPlatformMXBeanProxy}(mbs, 129 ManagementFactory.RUNTIME_MXBEAN_NAME, 130 RuntimeMXBean.class); 131 </pre> 132 </li> 133 </ul> 134 <p> 135 <b>2. Indirect access to an MXBean interface via MBeanServer</b><p> 136 <ul> 137 <li>Go through the 138 {@link java.lang.management.ManagementFactory#getPlatformMBeanServer 139 platform MBeanServer} to access MXBeans locally or 140 a specific {@code MBeanServerConnection} to access 141 MXBeans remotely. 142 The attributes and operations of an MXBean use only 143 <em>JMX open types</em> which include basic data types, 144 {@link javax.management.openmbean.CompositeData CompositeData}, 145 and {@link javax.management.openmbean.TabularData TabularData} 146 defined in {@link javax.management.openmbean.OpenType OpenType}.<p> 147 <pre> 148 MBeanServerConnection mbs; 149 150 // Connect to a running JVM (or itself) and get MBeanServerConnection 151 // that has the JVM MXBeans registered in it 152 ... 153 154 try { 155 // Assuming the RuntimeMXBean has been registered in mbs 156 ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME); 157 158 // Get standard attribute "VmVendor" 159 String vendor = (String) mbs.getAttribute(oname, "VmVendor"); 160 } catch (....) { 161 // Catch the exceptions thrown by ObjectName constructor 162 // and MBeanServer.getAttribute method 163 ... 164 } 165 </pre> 166 </li> | 14 version 2 for more details (a copy is included in the LICENSE file that 15 accompanied this code). 16 17 You should have received a copy of the GNU General Public License version 18 2 along with this work; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 21 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 or visit www.oracle.com if you need additional information or have any 23 questions. 24 --> 25 26 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 27 <html> 28 <body bgcolor="white"> 29 30 Provides the management interfaces for monitoring and management of the 31 Java virtual machine and other components in the Java runtime. 32 It allows both local and remote 33 monitoring and management of the running Java virtual machine. 34 35 <h4><a name="MXBean">Platform MXBean</a></h4> 36 <p> 37 A platform MXBean is a <i>managed bean</i> that 38 conforms to the <a href="../../../javax/management/package-summary.html">JMX</a> 39 Instrumentation Specification and only uses a set of basic data types. 40 Each platform MXBean is a {@link java.lang.management.PlatformManagedObject} 41 with a unique 42 {@linkplain java.lang.management.PlatformManagedObject#getObjectName name}. 43 <h4>ManagementFactory</h4> 44 45 <p>The {@link java.lang.management.ManagementFactory} class is the management 46 factory class for the Java platform. This class provides a set of 47 static factory methods to obtain the MXBeans for the Java platform 48 to allow an application to access the MXBeans directly. 49 50 <p>A <em>platform MBeanServer</em> can be accessed with the 51 {@link java.lang.management.ManagementFactory#getPlatformMBeanServer 52 getPlatformMBeanServer} method. On the first call to this method, 53 it creates the platform MBeanServer and registers all platform MXBeans 54 including {@linkplain java.lang.management.PlatformManagedObject 55 platform MXBeans}. 56 Each platform MXBean is registered with a unique name defined in 57 the specification of the management interface. 58 This is a single MBeanServer that can be shared by different managed 59 components running within the same Java virtual machine. 60 61 <h4>Interoperability</h4> 62 63 <p>A management application and a platform MBeanServer of a running 64 virtual machine can interoperate 65 without requiring classes used by the platform MXBean interfaces. 66 The data types being transmitted between the JMX connector 67 server and the connector client are JMX 68 {@linkplain javax.management.openmbean.OpenType open types} and 69 this allows interoperation across versions. 70 A data type used by the MXBean interfaces are mapped to an 71 open type when being accessed via MBeanServer interface. 72 See the <a href="../../../javax/management/MXBean.html#MXBean-spec"> 73 MXBean</a> specification for details. 74 75 <h4><a name="examples">Ways to Access MXBeans</a></h4> 76 77 <p>An application can monitor the instrumentation of the 78 Java virtual machine and the runtime in the following ways: 79 <p> 80 <b>1. Direct access to an MXBean interface</b> 81 <ul> 82 <li>Get an MXBean instance locally in the running Java virtual machine: 83 <pre> 84 RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean(); 85 86 // Get the standard attribute "VmVendor" 87 String vendor = mxbean.getVmVendor(); 88 </pre> 89 <p>Or by calling the 90 {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class) 91 getPlatformMXBean} or 92 {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class) 93 getPlatformMXBeans} method: 94 <pre> 95 RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); 96 97 // Get the standard attribute "VmVendor" 98 String vendor = mxbean.getVmVendor(); 99 </pre> 100 </li> 101 <li>Construct an MXBean proxy instance that forwards the 102 method calls to a given MBeanServer: 103 <pre> 104 MBeanServerConnection mbs; 105 106 // Connect to a running JVM (or itself) and get MBeanServerConnection 107 // that has the JVM MBeans registered in it 108 ... 109 110 // Get a MBean proxy for RuntimeMXBean interface 111 RuntimeMXBean proxy = 112 {@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class) 113 ManagementFactory.getPlatformMXBean}(mbs, 114 RuntimeMXBean.class); 115 // Get standard attribute "VmVendor" 116 String vendor = proxy.getVmVendor(); 117 </pre> 118 <p>A proxy is typically used to access an MXBean 119 in a remote Java virtual machine. 120 An alternative way to create an MXBean proxy is: 121 <pre> 122 RuntimeMXBean proxy = 123 {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy 124 ManagementFactory.newPlatformMXBeanProxy}(mbs, 125 ManagementFactory.RUNTIME_MXBEAN_NAME, 126 RuntimeMXBean.class); 127 </pre> 128 </li> 129 </ul> 130 <p> 131 <b>2. Indirect access to an MXBean interface via MBeanServer</b> 132 <ul> 133 <li>Go through the 134 {@link java.lang.management.ManagementFactory#getPlatformMBeanServer 135 platform MBeanServer} to access MXBeans locally or 136 a specific {@code MBeanServerConnection} to access 137 MXBeans remotely. 138 The attributes and operations of an MXBean use only 139 <em>JMX open types</em> which include basic data types, 140 {@link javax.management.openmbean.CompositeData CompositeData}, 141 and {@link javax.management.openmbean.TabularData TabularData} 142 defined in {@link javax.management.openmbean.OpenType OpenType}. 143 <pre> 144 MBeanServerConnection mbs; 145 146 // Connect to a running JVM (or itself) and get MBeanServerConnection 147 // that has the JVM MXBeans registered in it 148 ... 149 150 try { 151 // Assuming the RuntimeMXBean has been registered in mbs 152 ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME); 153 154 // Get standard attribute "VmVendor" 155 String vendor = (String) mbs.getAttribute(oname, "VmVendor"); 156 } catch (....) { 157 // Catch the exceptions thrown by ObjectName constructor 158 // and MBeanServer.getAttribute method 159 ... 160 } 161 </pre> 162 </li> |