Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
0e37d88a
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0e37d88a
编写于
3月 29, 2011
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
Reviewed-by: alanb
上级
7254cc99
变更
16
显示空白变更内容
内联
并排
Showing
16 changed file
with
1023 addition
and
592 deletion
+1023
-592
src/share/classes/java/lang/management/BufferPoolMXBean.java
src/share/classes/java/lang/management/BufferPoolMXBean.java
+9
-10
src/share/classes/java/lang/management/ManagementFactory.java
...share/classes/java/lang/management/ManagementFactory.java
+208
-213
src/share/classes/java/lang/management/PlatformComponent.java
...share/classes/java/lang/management/PlatformComponent.java
+89
-17
src/share/classes/java/lang/management/PlatformLoggingMXBean.java
...e/classes/java/lang/management/PlatformLoggingMXBean.java
+138
-0
src/share/classes/java/lang/management/PlatformManagedObject.java
...e/classes/java/lang/management/PlatformManagedObject.java
+1
-1
src/share/classes/java/lang/management/package.html
src/share/classes/java/lang/management/package.html
+120
-176
src/share/classes/java/util/logging/LogManager.java
src/share/classes/java/util/logging/LogManager.java
+13
-8
src/share/classes/java/util/logging/LoggingMXBean.java
src/share/classes/java/util/logging/LoggingMXBean.java
+24
-19
src/share/classes/java/util/logging/PlatformLoggingMXBean.java
...hare/classes/java/util/logging/PlatformLoggingMXBean.java
+0
-60
src/share/classes/sun/management/ManagementFactoryHelper.java
...share/classes/sun/management/ManagementFactoryHelper.java
+62
-45
test/Makefile
test/Makefile
+2
-2
test/java/lang/management/BufferPoolMXBean/Basic.java
test/java/lang/management/BufferPoolMXBean/Basic.java
+25
-15
test/java/lang/management/ManagementFactory/GetPlatformMXBeans.java
...lang/management/ManagementFactory/GetPlatformMXBeans.java
+94
-14
test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java
...g/management/PlatformLoggingMXBean/LoggingMXBeanTest.java
+229
-0
test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java
...ment/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java
+8
-11
test/java/nio/channels/AsynchronousSocketChannel/Leaky.java
test/java/nio/channels/AsynchronousSocketChannel/Leaky.java
+1
-1
未找到文件。
src/share/classes/java/
nio
/BufferPoolMXBean.java
→
src/share/classes/java/
lang/management
/BufferPoolMXBean.java
浏览文件 @
0e37d88a
...
@@ -23,15 +23,15 @@
...
@@ -23,15 +23,15 @@
* questions.
* questions.
*/
*/
package
java.nio
;
package
java.lang.management
;
import
java.lang.management.PlatformManagedObject
;
/**
/**
* The management interface for a buffer pool.
* The management interface for a buffer pool, for example a pool of
* {@link java.nio.ByteBuffer#allocateDirect direct} or {@link
* java.nio.MappedByteBuffer mapped} buffers.
*
*
* <p> A class implementing this interface is an
<a href=
* <p> A class implementing this interface is an
*
"java.lang.management.ManagementFactory.html#MXBean">MXBean</a>
. A Java
*
{@link javax.management.MXBean}
. A Java
* virtual machine has one or more implementations of this interface. The {@link
* virtual machine has one or more implementations of this interface. The {@link
* java.lang.management.ManagementFactory#getPlatformMXBeans getPlatformMXBeans}
* java.lang.management.ManagementFactory#getPlatformMXBeans getPlatformMXBeans}
* method can be used to obtain the list of {@code BufferPoolMXBean} objects
* method can be used to obtain the list of {@code BufferPoolMXBean} objects
...
@@ -44,14 +44,13 @@ import java.lang.management.PlatformManagedObject;
...
@@ -44,14 +44,13 @@ import java.lang.management.PlatformManagedObject;
* javax.management.MBeanServer MBeanServer}. The {@link
* javax.management.MBeanServer MBeanServer}. The {@link
* javax.management.ObjectName ObjectName} that uniquely identifies the
* javax.management.ObjectName ObjectName} that uniquely identifies the
* management interface within the {@code MBeanServer} takes the form:
* management interface within the {@code MBeanServer} takes the form:
* <
blockquot
e>
* <
pr
e>
*
<tt>java.nio:type=BufferPool</tt><tt>,name=</tt>
<i>pool name</i>
*
java.nio:type=BufferPool,name=
<i>pool name</i>
* </
blockquot
e>
* </
pr
e>
* where <em>pool name</em> is the {@link #getName name} of the buffer pool.
* where <em>pool name</em> is the {@link #getName name} of the buffer pool.
*
*
* @since 1.7
* @since 1.7
*/
*/
public
interface
BufferPoolMXBean
extends
PlatformManagedObject
{
public
interface
BufferPoolMXBean
extends
PlatformManagedObject
{
/**
/**
...
...
src/share/classes/java/lang/management/ManagementFactory.java
浏览文件 @
0e37d88a
...
@@ -40,8 +40,9 @@ import javax.management.NotCompliantMBeanException;
...
@@ -40,8 +40,9 @@ import javax.management.NotCompliantMBeanException;
import
javax.management.StandardEmitterMBean
;
import
javax.management.StandardEmitterMBean
;
import
javax.management.StandardMBean
;
import
javax.management.StandardMBean
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.security.AccessController
;
import
java.security.AccessController
;
import
java.security.Permission
;
import
java.security.Permission
;
import
java.security.PrivilegedAction
;
import
java.security.PrivilegedAction
;
...
@@ -51,37 +52,63 @@ import javax.management.JMX;
...
@@ -51,37 +52,63 @@ import javax.management.JMX;
import
sun.management.ManagementFactoryHelper
;
import
sun.management.ManagementFactoryHelper
;
/**
/**
* The
<tt>ManagementFactory</tt>
class is a factory class for getting
* The
{@code ManagementFactory}
class is a factory class for getting
* managed beans for the Java platform.
* managed beans for the Java platform.
* This class consists of static methods each of which returns
* This class consists of static methods each of which returns
* one or more <
a href="#MXBean">platform MXBean(s)</a
> representing
* one or more <
i>platform MXBeans</i
> representing
* the management interface of a component of the Java virtual
* the management interface of a component of the Java virtual
* machine.
* machine.
* <p>
* <h4><a name="MXBean">Platform MXBeans</a></h4>
* <p>
* A platform MXBean is a <i>managed bean</i> that
* conforms to the <a href="../../../javax/management/package-summary.html">JMX</a>
* Instrumentation Specification and only uses a set of basic data types.
* A JMX management application and the {@linkplain
* #getPlatformMBeanServer platform MBeanServer}
* can interoperate without requiring classes for MXBean specific
* data types.
* The data types being transmitted between the JMX connector
* server and the connector client are
* {@linkplain javax.management.openmbean.OpenType open types}
* and this allows interoperation across versions.
* See <a href="../../../javax/management/MXBean.html#MXBean-spec">
* the specification of MXBeans</a> for details.
*
* <a name="MXBeanNames"></a>
* <p>Each platform MXBean is a {@link PlatformManagedObject}
* and it has a unique
* {@link javax.management.ObjectName ObjectName} for
* registration in the platform {@code MBeanServer} as returned by
* by the {@link PlatformManagedObject#getObjectName getObjectName}
* method.
*
*
* <p>
* <p>
* An application can access a platform MXBean in the following ways:
* An application can access a platform MXBean in the following ways:
* <h5>1. Direct access to an MXBean interface</h5>
* <blockquote>
* <ul>
* <ul>
* <li><i>Direct access to an MXBean interface</i>
* <li>Get an MXBean instance by calling the
* <ol type="a">
* {@link #getPlatformMXBean(Class) getPlatformMXBean} or
* <li>Get the MXBean instance through the static factory method,
* {@link #getPlatformMXBeans(Class) getPlatformMXBeans} method
* or the {@link #getPlatformMXBeans(Class)} method
* and access the MXBean locally in the running
* and access the MXBean locally of the running
* virtual machine.
* virtual machine.
* </li>
* </li>
* <li>Construct an MXBean proxy instance that forwards the
* <li>Construct an MXBean proxy instance that forwards the
* method calls to a given {@link MBeanServer MBeanServer} by calling
* method calls to a given {@link MBeanServer MBeanServer} by calling
* the {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method
* the {@link #getPlatformMXBean(MBeanServerConnection, Class)} or
* or the {@link #getPlatformMXBeans(MBeanServerConnection, Class)}
* {@link #getPlatformMXBeans(MBeanServerConnection, Class)} method.
* method.
* The {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method
* can also be used to construct an MXBean proxy instance of
* a given {@code ObjectName}.
* A proxy is typically constructed to remotely access
* A proxy is typically constructed to remotely access
* an MXBean of another running virtual machine.
* an MXBean of another running virtual machine.
* </li>
* </li>
* </ol></li>
* </ul>
* <li><i>Indirect access to an MXBean interface via MBeanServer</i>
* <h5>2. Indirect access to an MXBean interface via MBeanServer</h5>
* <ol type="a">
* <ul>
* <li>Go through the {@link #getPlatformMBeanServer
* <li>Go through the platform {@code MBeanServer} to access MXBeans
* platform MBeanServer} to access MXBeans locally or
* locally or a specific <tt>MBeanServerConnection</tt> to access
* a specific <tt>MBeanServerConnection</tt> to access
* MXBeans remotely.
* MXBeans remotely.
* The attributes and operations of an MXBean use only
* The attributes and operations of an MXBean use only
* <em>JMX open types</em> which include basic data types,
* <em>JMX open types</em> which include basic data types,
...
@@ -89,133 +116,19 @@ import sun.management.ManagementFactoryHelper;
...
@@ -89,133 +116,19 @@ import sun.management.ManagementFactoryHelper;
* and {@link javax.management.openmbean.TabularData TabularData}
* and {@link javax.management.openmbean.TabularData TabularData}
* defined in
* defined in
* {@link javax.management.openmbean.OpenType OpenType}.
* {@link javax.management.openmbean.OpenType OpenType}.
* The mapping is specified below.
* The mapping is specified in
* </li>
* the {@linkplain javax.management.MXBean MXBean} specification
* </ol></li>
* for details.
* </ul>
*
* <h4><a name="MXBean">Platform MXBeans</a></h4>
* A platform MXBean is a <i>managed bean</i> that conforms to
* the JMX Instrumentation Specification and only uses
* a set of basic data types described below.
* See <a href="../../../javax/management/MXBean.html#MXBean-spec">
* the specification of MXBeans</a> for details.
* All platform MXBean interfaces extend {@link PlatformManagedObject}s
* and new methods may be added in these interfaces
* in future Java SE releases.
* <p>
* A JMX management application and the platform <tt>MBeanServer</tt>
* can interoperate without requiring classes for MXBean specific
* data types.
* The data types being transmitted between the JMX connector
* server and the connector client are
* {@linkplain javax.management.openmbean.OpenType open types}
* and this allows interoperation across versions.
* <p>
* The platform MXBean interfaces use only the following data types:
* <ul>
* <li>Primitive types such as <tt>int</tt>, <tt>long</tt>,
* <tt>boolean</tt>, etc</li>
* <li>Wrapper classes for primitive types such as
* {@link java.lang.Integer Integer}, {@link java.lang.Long Long},
* {@link java.lang.Boolean Boolean}, etc and
* {@link java.lang.String String}</li>
* <li>{@link java.lang.Enum Enum} classes</li>
* <li>Classes that define only getter methods and define a static
* <tt>from</tt> method with a
* {@link javax.management.openmbean.CompositeData CompositeData}
* argument to convert from an input <tt>CompositeData</tt> to
* an instance of that class
* </li>
* <li>{@link java.util.List List<E>}
* where <tt>E</tt> is a primitive type, a wrapper class,
* an enum class, or a class supporting conversion from a
* <tt>CompositeData</tt> to its class
* </li>
* <li>{@link java.util.Map Map<K,V>}
* where <tt>K</tt> and <tt>V</tt> are
* a primitive type, a wrapper class,
* an enum class, or a class supporting conversion from a
* <tt>CompositeData</tt> to its class
* </li>
* </li>
* </ul>
* </ul>
* </blockquote>
*
*
* <p>
* <p>
* When an attribute or operation of a platform MXBean
* The {@link #getPlatformManagementInterfaces getPlatformManagementInterfaces}
* is accessed via an <tt>MBeanServer</tt>, the data types are mapped
* method returns all management interfaces supported in the Java virtual machine
* as follows:
* including the standard management interfaces listed in the tables
* <ul>
* below as well as the management interfaces extended by the JDK implementation.
* <li>A primitive type or a wrapper class is mapped
* to the same type.
* </li>
* <li>An {@link Enum} is mapped to
* <tt>String</tt> whose value is the name of the enum constant.
* <li>A class that defines only getter methods and a static
* <tt>from</tt> method with a
* {@link javax.management.openmbean.CompositeData CompositeData}
* argument is mapped to
* {@link javax.management.openmbean.CompositeData CompositeData}.
* </li>
* <li><tt>Map<K,V></tt> is mapped to
* {@link javax.management.openmbean.TabularData TabularData}
* whose row type is a
* {@link javax.management.openmbean.CompositeType CompositeType} with
* two items whose names are <i>"key"</i> and <i>"value"</i>
* and the item types are
* the corresponding mapped type of <tt>K</tt> and <tt>V</tt>
* respectively and the <i>"key"</i> is the index.
* </li>
* <li><tt>List<E></tt> is mapped to an array with the mapped
* type of <tt>E</tt> as the element type.
* </li>
* <li>An array of element type <tt>E</tt> is mapped to
* an array of the same dimenions with the mapped type of <tt>E</tt>
* as the element type.</li>
* </ul>
*
* The {@link javax.management.MBeanInfo MBeanInfo}
* for a platform MXBean
* describes the data types of the attributes and operations
* as primitive or open types mapped as specified above.
*
* <p>
* <p>
* For example, the {@link MemoryMXBean}
* interface has the following <i>getter</i> and <i>setter</i> methods:
*
* <blockquote><pre>
* public MemoryUsage getHeapMemoryUsage();
* public boolean isVerbose();
* public void setVerbose(boolean value);
* </pre></blockquote>
*
* These attributes in the <tt>MBeanInfo</tt>
* of the <tt>MemoryMXBean</tt> have the following names and types:
*
* <blockquote>
* <table border>
* <tr>
* <th>Attribute Name</th>
* <th>Type</th>
* </tr>
* <tr>
* <td><tt>HeapMemoryUsage</tt></td>
* <td>{@link MemoryUsage#from
* CompositeData representing MemoryUsage}</td>
* </tr>
* <tr>
* <td><tt>Verbose</tt></td>
* <td><tt>boolean</tt></td>
* </tr>
* </table>
* </blockquote>
*
* <h4><a name="MXBeanNames">MXBean Names</a></h4>
* Each platform MXBean for a Java virtual machine has a unique
* {@link javax.management.ObjectName ObjectName} for
* registration in the platform <tt>MBeanServer</tt> that can
* be obtained by calling the {@link PlatformManagedObject#getObjectName}
* method.
*
* A Java virtual machine has a single instance of the following management
* A Java virtual machine has a single instance of the following management
* interfaces:
* interfaces:
*
*
...
@@ -228,27 +141,32 @@ import sun.management.ManagementFactoryHelper;
...
@@ -228,27 +141,32 @@ import sun.management.ManagementFactoryHelper;
* <tr>
* <tr>
* <td> {@link ClassLoadingMXBean} </td>
* <td> {@link ClassLoadingMXBean} </td>
* <td> {@link #CLASS_LOADING_MXBEAN_NAME
* <td> {@link #CLASS_LOADING_MXBEAN_NAME
*
<tt>java.lang:type=ClassLoading</tt>
}</td>
*
java.lang:type=ClassLoading
}</td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link MemoryMXBean} </td>
* <td> {@link MemoryMXBean} </td>
* <td> {@link #MEMORY_MXBEAN_NAME
* <td> {@link #MEMORY_MXBEAN_NAME
*
<tt>java.lang:type=Memory</tt>
}</td>
*
java.lang:type=Memory
}</td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link ThreadMXBean} </td>
* <td> {@link ThreadMXBean} </td>
* <td> {@link #THREAD_MXBEAN_NAME
* <td> {@link #THREAD_MXBEAN_NAME
*
<tt>java.lang:type=Threading</tt>
}</td>
*
java.lang:type=Threading
}</td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link RuntimeMXBean} </td>
* <td> {@link RuntimeMXBean} </td>
* <td> {@link #RUNTIME_MXBEAN_NAME
* <td> {@link #RUNTIME_MXBEAN_NAME
*
<tt>java.lang:type=Runtime</tt>
}</td>
*
java.lang:type=Runtime
}</td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link OperatingSystemMXBean} </td>
* <td> {@link OperatingSystemMXBean} </td>
* <td> {@link #OPERATING_SYSTEM_MXBEAN_NAME
* <td> {@link #OPERATING_SYSTEM_MXBEAN_NAME
* <tt>java.lang:type=OperatingSystem</tt>}</td>
* java.lang:type=OperatingSystem}</td>
* </tr>
* <tr>
* <td> {@link PlatformLoggingMXBean} </td>
* <td> {@link java.util.logging.LogManager#LOGGING_MXBEAN_NAME
* java.util.logging:type=Logging}</td>
* </tr>
* </tr>
* </table>
* </table>
* </blockquote>
* </blockquote>
...
@@ -266,7 +184,7 @@ import sun.management.ManagementFactoryHelper;
...
@@ -266,7 +184,7 @@ import sun.management.ManagementFactoryHelper;
* <tr>
* <tr>
* <td> {@link CompilationMXBean} </td>
* <td> {@link CompilationMXBean} </td>
* <td> {@link #COMPILATION_MXBEAN_NAME
* <td> {@link #COMPILATION_MXBEAN_NAME
*
<tt>java.lang:type=Compilation</tt>
}</td>
*
java.lang:type=Compilation
}</td>
* </tr>
* </tr>
* </table>
* </table>
* </blockquote>
* </blockquote>
...
@@ -283,17 +201,21 @@ import sun.management.ManagementFactoryHelper;
...
@@ -283,17 +201,21 @@ import sun.management.ManagementFactoryHelper;
* <tr>
* <tr>
* <td> {@link GarbageCollectorMXBean} </td>
* <td> {@link GarbageCollectorMXBean} </td>
* <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
* <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
*
<tt>java.lang:type=GarbageCollector</tt>
}<tt>,name=</tt><i>collector's name</i></td>
*
java.lang:type=GarbageCollector
}<tt>,name=</tt><i>collector's name</i></td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link MemoryManagerMXBean} </td>
* <td> {@link MemoryManagerMXBean} </td>
* <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
* <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
*
<tt>java.lang:type=MemoryManager</tt>
}<tt>,name=</tt><i>manager's name</i></td>
*
java.lang:type=MemoryManager
}<tt>,name=</tt><i>manager's name</i></td>
* </tr>
* </tr>
* <tr>
* <tr>
* <td> {@link MemoryPoolMXBean} </td>
* <td> {@link MemoryPoolMXBean} </td>
* <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE
* <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE
* <tt>java.lang:type=MemoryPool</tt>}<tt>,name=</tt><i>pool's name</i></td>
* java.lang:type=MemoryPool}<tt>,name=</tt><i>pool's name</i></td>
* </tr>
* <tr>
* <td> {@link BufferPoolMXBean} </td>
* <td> {@code java.nio:type=BufferPool,name=}<i>pool name</i></td>
* </tr>
* </tr>
* </table>
* </table>
* </blockquote>
* </blockquote>
...
@@ -302,7 +224,6 @@ import sun.management.ManagementFactoryHelper;
...
@@ -302,7 +224,6 @@ import sun.management.ManagementFactoryHelper;
* JMX Specification</a>
* JMX Specification</a>
* @see <a href="package-summary.html#examples">
* @see <a href="package-summary.html#examples">
* Ways to Access Management Metrics</a>
* Ways to Access Management Metrics</a>
* @see java.util.logging.LoggingMXBean
* @see javax.management.MXBean
* @see javax.management.MXBean
*
*
* @author Mandy Chung
* @author Mandy Chung
...
@@ -496,35 +417,35 @@ public class ManagementFactory {
...
@@ -496,35 +417,35 @@ public class ManagementFactory {
/**
/**
* Returns the platform {@link javax.management.MBeanServer MBeanServer}.
* Returns the platform {@link javax.management.MBeanServer MBeanServer}.
* On the first call to this method, it first creates the platform
* On the first call to this method, it first creates the platform
*
<tt>MBeanServer</tt>
by calling the
*
{@code MBeanServer}
by calling the
* {@link javax.management.MBeanServerFactory#createMBeanServer
* {@link javax.management.MBeanServerFactory#createMBeanServer
* MBeanServerFactory.createMBeanServer}
* MBeanServerFactory.createMBeanServer}
* method and registers
the platform MXBeans
in this platform
* method and registers
each platform MXBean
in this platform
*
<tt>MBeanServer</tt> using the <a href="#MXBeanNames">MXBean names</a>
*
{@code MBeanServer} with its
*
defined in the class description
.
*
{@link PlatformManagedObject#getObjectName ObjectName}
.
* This method, in subsequent calls, will simply return the
* This method, in subsequent calls, will simply return the
* initially created platform
<tt>MBeanServer</tt>
.
* initially created platform
{@code MBeanServer}
.
* <p>
* <p>
* MXBeans that get created and destroyed dynamically, for example,
* MXBeans that get created and destroyed dynamically, for example,
* memory {@link MemoryPoolMXBean pools} and
* memory {@link MemoryPoolMXBean pools} and
* {@link MemoryManagerMXBean managers},
* {@link MemoryManagerMXBean managers},
* will automatically be registered and deregistered into the platform
* will automatically be registered and deregistered into the platform
*
<tt>MBeanServer</tt>
.
*
{@code MBeanServer}
.
* <p>
* <p>
* If the system property
<tt>javax.management.builder.initial</tt>
* If the system property
{@code javax.management.builder.initial}
* is set, the platform
<tt>MBeanServer</tt>
creation will be done
* is set, the platform
{@code MBeanServer}
creation will be done
* by the specified {@link javax.management.MBeanServerBuilder}.
* by the specified {@link javax.management.MBeanServerBuilder}.
* <p>
* <p>
* It is recommended that this platform MBeanServer also be used
* It is recommended that this platform MBeanServer also be used
* to register other application managed beans
* to register other application managed beans
* besides the platform MXBeans.
* besides the platform MXBeans.
* This will allow all MBeans to be published through the same
* This will allow all MBeans to be published through the same
*
<tt>MBeanServer</tt>
and hence allow for easier network publishing
*
{@code MBeanServer}
and hence allow for easier network publishing
* and discovery.
* and discovery.
* Name conflicts with the platform MXBeans should be avoided.
* Name conflicts with the platform MXBeans should be avoided.
*
*
* @return the platform
<tt>MBeanServer</tt>
; the platform
* @return the platform
{@code MBeanServer}
; the platform
* MXBeans are registered into the platform
<tt>MBeanServer</tt>
* MXBeans are registered into the platform
{@code MBeanServer}
* at the first time this method is called.
* at the first time this method is called.
*
*
* @exception SecurityException if there is a security manager
* @exception SecurityException if there is a security manager
...
@@ -671,7 +592,9 @@ public class ManagementFactory {
...
@@ -671,7 +592,9 @@ public class ManagementFactory {
try
{
try
{
final
ObjectName
objName
=
new
ObjectName
(
mxbeanName
);
final
ObjectName
objName
=
new
ObjectName
(
mxbeanName
);
if
(!
connection
.
isInstanceOf
(
objName
,
interfaceClass
.
getName
()))
{
// skip the isInstanceOf check for LoggingMXBean
String
intfName
=
interfaceClass
.
getName
();
if
(!
connection
.
isInstanceOf
(
objName
,
intfName
))
{
throw
new
IllegalArgumentException
(
mxbeanName
+
throw
new
IllegalArgumentException
(
mxbeanName
+
" is not an instance of "
+
interfaceClass
);
" is not an instance of "
+
interfaceClass
);
}
}
...
@@ -683,55 +606,128 @@ public class ManagementFactory {
...
@@ -683,55 +606,128 @@ public class ManagementFactory {
// create an MXBean proxy
// create an MXBean proxy
return
JMX
.
newMXBeanProxy
(
connection
,
objName
,
mxbeanInterface
,
return
JMX
.
newMXBeanProxy
(
connection
,
objName
,
mxbeanInterface
,
emitter
);
emitter
);
}
catch
(
InstanceNotFoundException
e
)
{
}
catch
(
InstanceNotFoundException
|
MalformedObjectNameException
e
)
{
final
IllegalArgumentException
iae
=
throw
new
IllegalArgumentException
(
e
);
new
IllegalArgumentException
(
mxbeanName
+
" not found in the connection."
);
iae
.
initCause
(
e
);
throw
iae
;
}
catch
(
MalformedObjectNameException
e
)
{
final
IllegalArgumentException
iae
=
new
IllegalArgumentException
(
mxbeanName
+
" is not a valid ObjectName format."
);
iae
.
initCause
(
e
);
throw
iae
;
}
}
}
}
/**
/**
* Returns the list of platform MXBeans that implement
* Returns the platform MXBean implementing
* the given {@code mxbeanInterface} in the running Java
* the given {@code mxbeanInterface} which is specified
* to have one single instance in the Java virtual machine.
* This method may return {@code null} if the management interface
* is not implemented in the Java virtual machine (for example,
* a Java virtual machine with no compilation system does not
* implement {@link CompilationMXBean});
* otherwise, this method is equivalent to calling:
* <pre>
* {@link #getPlatformMXBeans(Class)
* getPlatformMXBeans(mxbeanInterface)}.get(0);
* </pre>
*
* @param mxbeanInterface a management interface for a platform
* MXBean with one single instance in the Java virtual machine
* if implemented.
*
* @return the platform MXBean that implements
* {@code mxbeanInterface}, or {@code null} if not exist.
*
* @throws IllegalArgumentException if {@code mxbeanInterface}
* is not a platform management interface or
* not a singleton platform MXBean.
*
* @since 1.7
*/
public
static
<
T
extends
PlatformManagedObject
>
T
getPlatformMXBean
(
Class
<
T
>
mxbeanInterface
)
{
PlatformComponent
pc
=
PlatformComponent
.
getPlatformComponent
(
mxbeanInterface
);
if
(
pc
==
null
)
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
" is not a platform management interface"
);
if
(!
pc
.
isSingleton
())
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
" can have zero or more than one instances"
);
return
pc
.
getSingletonMXBean
(
mxbeanInterface
);
}
/**
* Returns the list of platform MXBeans implementing
* the given {@code mxbeanInterface} in the Java
* virtual machine.
* virtual machine.
* The returned list may contain zero, one, or more instances.
* The returned list may contain zero, one, or more instances.
* The number of instances in the returned list is defined
* The number of instances in the returned list is defined
* in the specification of the given management interface.
* in the specification of the given management interface.
* The order is undefined and there is no guarantee that
* the list returned is in the same order as previous invocations.
*
*
* @param mxbeanInterface a management interface for a platform
* @param mxbeanInterface a management interface for a platform
* MXBean
* MXBean
*
*
* @return the list of platform MXBeans that implement
s
* @return the list of platform MXBeans that implement
* {@code mxbeanInterface}.
* {@code mxbeanInterface}.
*
*
* @throws IllegalArgumentException if {@code mxbeanInterface}
* @throws IllegalArgumentException if {@code mxbeanInterface}
* is not a
management interface for the platform
.
* is not a
platform management interface
.
*
*
* @since 1.7
* @since 1.7
*/
*/
public
static
<
T
extends
PlatformManagedObject
>
List
<
T
>
public
static
<
T
extends
PlatformManagedObject
>
List
<
T
>
getPlatformMXBeans
(
Class
<
T
>
mxbeanInterface
)
{
getPlatformMXBeans
(
Class
<
T
>
mxbeanInterface
)
{
String
className
=
mxbeanInterface
.
getName
();
PlatformComponent
pc
=
PlatformComponent
.
getPlatformComponent
(
mxbeanInterface
);
for
(
PlatformComponent
component:
PlatformComponent
.
values
())
{
if
(
pc
==
null
)
// comparing the class name first instead of the Class instance
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
// to avoid causing unnecessary class loading of
" is not a platform management interface"
);
// the other MXBean interfaces
return
Collections
.
unmodifiableList
(
pc
.
getMXBeans
(
mxbeanInterface
));
if
(
className
.
equals
(
component
.
getMXBeanInterfaceName
()))
{
if
(
component
.
getMXBeanInterface
()
==
mxbeanInterface
)
{
return
component
.
getMXBeans
(
mxbeanInterface
);
}
}
}
}
/**
* Returns the platform MXBean proxy for
* {@code mxbeanInterface} which is specified to have one single
* instance in a Java virtual machine and the proxy will
* forward the method calls through the given {@code MBeanServerConnection}.
* This method may return {@code null} if the management interface
* is not implemented in the Java virtual machine being monitored
* (for example, a Java virtual machine with no compilation system
* does not implement {@link CompilationMXBean});
* otherwise, this method is equivalent to calling:
* <pre>
* {@link #getPlatformMXBeans(MBeanServerConnection, Class)
* getPlatformMXBeans(connection, mxbeanInterface)}.get(0);
* </pre>
*
* @param connection the {@code MBeanServerConnection} to forward to.
* @param mxbeanInterface a management interface for a platform
* MXBean with one single instance in the Java virtual machine
* being monitored, if implemented.
*
* @return the platform MXBean proxy for
* forwarding the method calls of the {@code mxbeanInterface}
* through the given {@code MBeanServerConnection},
* or {@code null} if not exist.
*
* @throws IllegalArgumentException if {@code mxbeanInterface}
* is not a platform management interface or
* not a singleton platform MXBean.
* @throws java.io.IOException if a communication problem
* occurred when accessing the {@code MBeanServerConnection}.
*
* @see #newPlatformMXBeanProxy
* @since 1.7
*/
public
static
<
T
extends
PlatformManagedObject
>
T
getPlatformMXBean
(
MBeanServerConnection
connection
,
Class
<
T
>
mxbeanInterface
)
throws
java
.
io
.
IOException
{
PlatformComponent
pc
=
PlatformComponent
.
getPlatformComponent
(
mxbeanInterface
);
if
(
pc
==
null
)
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
" is not a platform management interface"
);
if
(!
pc
.
isSingleton
())
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
" is not implemented by any of the platform MXBeans."
);
" can have zero or more than one instances"
);
return
pc
.
getSingletonMXBean
(
connection
,
mxbeanInterface
);
}
}
/**
/**
...
@@ -741,6 +737,8 @@ public class ManagementFactory {
...
@@ -741,6 +737,8 @@ public class ManagementFactory {
* The returned list may contain zero, one, or more instances.
* The returned list may contain zero, one, or more instances.
* The number of instances in the returned list is defined
* The number of instances in the returned list is defined
* in the specification of the given management interface.
* in the specification of the given management interface.
* The order is undefined and there is no guarantee that
* the list returned is in the same order as previous invocations.
*
*
* @param connection the {@code MBeanServerConnection} to forward to.
* @param connection the {@code MBeanServerConnection} to forward to.
* @param mxbeanInterface a management interface for a platform
* @param mxbeanInterface a management interface for a platform
...
@@ -751,11 +749,12 @@ public class ManagementFactory {
...
@@ -751,11 +749,12 @@ public class ManagementFactory {
* through the given {@code MBeanServerConnection}.
* through the given {@code MBeanServerConnection}.
*
*
* @throws IllegalArgumentException if {@code mxbeanInterface}
* @throws IllegalArgumentException if {@code mxbeanInterface}
* is not a
management interface for the platform
.
* is not a
platform management interface
.
*
*
* @throws java.io.IOException if a communication problem
* @throws java.io.IOException if a communication problem
* occurred when accessing the {@code MBeanServerConnection}.
* occurred when accessing the {@code MBeanServerConnection}.
*
*
* @see #newPlatformMXBeanProxy
* @since 1.7
* @since 1.7
*/
*/
public
static
<
T
extends
PlatformManagedObject
>
public
static
<
T
extends
PlatformManagedObject
>
...
@@ -763,42 +762,36 @@ public class ManagementFactory {
...
@@ -763,42 +762,36 @@ public class ManagementFactory {
Class
<
T
>
mxbeanInterface
)
Class
<
T
>
mxbeanInterface
)
throws
java
.
io
.
IOException
throws
java
.
io
.
IOException
{
{
String
className
=
mxbeanInterface
.
getName
();
PlatformComponent
pc
=
PlatformComponent
.
getPlatformComponent
(
mxbeanInterface
);
for
(
PlatformComponent
component:
PlatformComponent
.
values
())
{
if
(
pc
==
null
)
{
// comparing the class name first instead of the Class instance
// to avoid causing unnecessary class loading of
// the other MXBean interfaces
if
(
className
.
equals
(
component
.
getMXBeanInterfaceName
()))
{
if
(
component
.
getMXBeanInterface
()
==
mxbeanInterface
)
{
return
component
.
getMXBeans
(
connection
,
mxbeanInterface
);
}
}
}
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
throw
new
IllegalArgumentException
(
mxbeanInterface
.
getName
()
+
" is not implemented by any of the platform MXBeans."
);
" is not a platform management interface"
);
}
return
Collections
.
unmodifiableList
(
pc
.
getMXBeans
(
connection
,
mxbeanInterface
));
}
}
/**
/**
* Returns
a lis
t of {@code Class} objects, subinterface of
* Returns
the se
t of {@code Class} objects, subinterface of
* {@link PlatformManagedObject}, representing
* {@link PlatformManagedObject}, representing
* all management interfaces for
* all management interfaces for
* monitoring and managing the Java platform.
* monitoring and managing the Java platform.
*
*
* @return
a lis
t of {@code Class} objects, subinterface of
* @return
the se
t of {@code Class} objects, subinterface of
* {@link PlatformManagedObject} representing
* {@link PlatformManagedObject} representing
* the management interfaces for
* the management interfaces for
* monitoring and managing the Java platform.
* monitoring and managing the Java platform.
*
*
* @since 1.7
* @since 1.7
*/
*/
public
static
List
<
Class
<?
extends
PlatformManagedObject
>>
getAllPlatformMXBeanInterfaces
()
{
public
static
Set
<
Class
<?
extends
PlatformManagedObject
>>
List
<
Class
<?
extends
PlatformManagedObject
>>
result
=
getPlatformManagementInterfaces
()
new
ArrayList
<>();
{
Set
<
Class
<?
extends
PlatformManagedObject
>>
result
=
new
TreeSet
<>();
for
(
PlatformComponent
component:
PlatformComponent
.
values
())
{
for
(
PlatformComponent
component:
PlatformComponent
.
values
())
{
result
.
add
(
component
.
getMXBeanInterface
());
result
.
add
(
component
.
getMXBeanInterface
());
}
}
return
result
;
return
Collections
.
unmodifiableSet
(
result
)
;
}
}
private
static
final
String
NOTIF_EMITTER
=
private
static
final
String
NOTIF_EMITTER
=
...
@@ -810,7 +803,9 @@ public class ManagementFactory {
...
@@ -810,7 +803,9 @@ public class ManagementFactory {
private
static
void
addMXBean
(
final
MBeanServer
mbs
,
final
PlatformManagedObject
pmo
)
{
private
static
void
addMXBean
(
final
MBeanServer
mbs
,
final
PlatformManagedObject
pmo
)
{
// Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
// Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
final
DynamicMBean
dmbean
;
final
DynamicMBean
dmbean
;
if
(
pmo
instanceof
NotificationEmitter
)
{
if
(
pmo
instanceof
DynamicMBean
)
{
dmbean
=
DynamicMBean
.
class
.
cast
(
pmo
);
}
else
if
(
pmo
instanceof
NotificationEmitter
)
{
dmbean
=
new
StandardEmitterMBean
(
pmo
,
null
,
true
,
(
NotificationEmitter
)
pmo
);
dmbean
=
new
StandardEmitterMBean
(
pmo
,
null
,
true
,
(
NotificationEmitter
)
pmo
);
}
else
{
}
else
{
dmbean
=
new
StandardMBean
(
pmo
,
null
,
true
);
dmbean
=
new
StandardMBean
(
pmo
,
null
,
true
);
...
...
src/share/classes/java/lang/management/PlatformComponent.java
浏览文件 @
0e37d88a
...
@@ -29,9 +29,9 @@ import java.util.ArrayList;
...
@@ -29,9 +29,9 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.logging.PlatformLoggingMXBean
;
import
java.nio.BufferPoolMXBean
;
import
javax.management.MBeanServerConnection
;
import
javax.management.MBeanServerConnection
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
...
@@ -66,6 +66,7 @@ enum PlatformComponent {
...
@@ -66,6 +66,7 @@ enum PlatformComponent {
CLASS_LOADING
(
CLASS_LOADING
(
"java.lang.management.ClassLoadingMXBean"
,
"java.lang.management.ClassLoadingMXBean"
,
"java.lang"
,
"ClassLoading"
,
defaultKeyProperties
(),
"java.lang"
,
"ClassLoading"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
ClassLoadingMXBean
>()
{
new
MXBeanFetcher
<
ClassLoadingMXBean
>()
{
public
List
<
ClassLoadingMXBean
>
getMXBeans
()
{
public
List
<
ClassLoadingMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getClassLoadingMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getClassLoadingMXBean
());
...
@@ -78,6 +79,7 @@ enum PlatformComponent {
...
@@ -78,6 +79,7 @@ enum PlatformComponent {
COMPILATION
(
COMPILATION
(
"java.lang.management.CompilationMXBean"
,
"java.lang.management.CompilationMXBean"
,
"java.lang"
,
"Compilation"
,
defaultKeyProperties
(),
"java.lang"
,
"Compilation"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
CompilationMXBean
>()
{
new
MXBeanFetcher
<
CompilationMXBean
>()
{
public
List
<
CompilationMXBean
>
getMXBeans
()
{
public
List
<
CompilationMXBean
>
getMXBeans
()
{
CompilationMXBean
m
=
ManagementFactoryHelper
.
getCompilationMXBean
();
CompilationMXBean
m
=
ManagementFactoryHelper
.
getCompilationMXBean
();
...
@@ -95,6 +97,7 @@ enum PlatformComponent {
...
@@ -95,6 +97,7 @@ enum PlatformComponent {
MEMORY
(
MEMORY
(
"java.lang.management.MemoryMXBean"
,
"java.lang.management.MemoryMXBean"
,
"java.lang"
,
"Memory"
,
defaultKeyProperties
(),
"java.lang"
,
"Memory"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
MemoryMXBean
>()
{
new
MXBeanFetcher
<
MemoryMXBean
>()
{
public
List
<
MemoryMXBean
>
getMXBeans
()
{
public
List
<
MemoryMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getMemoryMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getMemoryMXBean
());
...
@@ -107,6 +110,7 @@ enum PlatformComponent {
...
@@ -107,6 +110,7 @@ enum PlatformComponent {
GARBAGE_COLLECTOR
(
GARBAGE_COLLECTOR
(
"java.lang.management.GarbageCollectorMXBean"
,
"java.lang.management.GarbageCollectorMXBean"
,
"java.lang"
,
"GarbageCollector"
,
keyProperties
(
"name"
),
"java.lang"
,
"GarbageCollector"
,
keyProperties
(
"name"
),
false
,
// zero or more instances
new
MXBeanFetcher
<
GarbageCollectorMXBean
>()
{
new
MXBeanFetcher
<
GarbageCollectorMXBean
>()
{
public
List
<
GarbageCollectorMXBean
>
getMXBeans
()
{
public
List
<
GarbageCollectorMXBean
>
getMXBeans
()
{
return
ManagementFactoryHelper
.
return
ManagementFactoryHelper
.
...
@@ -120,6 +124,7 @@ enum PlatformComponent {
...
@@ -120,6 +124,7 @@ enum PlatformComponent {
MEMORY_MANAGER
(
MEMORY_MANAGER
(
"java.lang.management.MemoryManagerMXBean"
,
"java.lang.management.MemoryManagerMXBean"
,
"java.lang"
,
"MemoryManager"
,
keyProperties
(
"name"
),
"java.lang"
,
"MemoryManager"
,
keyProperties
(
"name"
),
false
,
// zero or more instances
new
MXBeanFetcher
<
MemoryManagerMXBean
>()
{
new
MXBeanFetcher
<
MemoryManagerMXBean
>()
{
public
List
<
MemoryManagerMXBean
>
getMXBeans
()
{
public
List
<
MemoryManagerMXBean
>
getMXBeans
()
{
return
ManagementFactoryHelper
.
getMemoryManagerMXBeans
();
return
ManagementFactoryHelper
.
getMemoryManagerMXBeans
();
...
@@ -133,6 +138,7 @@ enum PlatformComponent {
...
@@ -133,6 +138,7 @@ enum PlatformComponent {
MEMORY_POOL
(
MEMORY_POOL
(
"java.lang.management.MemoryPoolMXBean"
,
"java.lang.management.MemoryPoolMXBean"
,
"java.lang"
,
"MemoryPool"
,
keyProperties
(
"name"
),
"java.lang"
,
"MemoryPool"
,
keyProperties
(
"name"
),
false
,
// zero or more instances
new
MXBeanFetcher
<
MemoryPoolMXBean
>()
{
new
MXBeanFetcher
<
MemoryPoolMXBean
>()
{
public
List
<
MemoryPoolMXBean
>
getMXBeans
()
{
public
List
<
MemoryPoolMXBean
>
getMXBeans
()
{
return
ManagementFactoryHelper
.
getMemoryPoolMXBeans
();
return
ManagementFactoryHelper
.
getMemoryPoolMXBeans
();
...
@@ -145,6 +151,7 @@ enum PlatformComponent {
...
@@ -145,6 +151,7 @@ enum PlatformComponent {
OPERATING_SYSTEM
(
OPERATING_SYSTEM
(
"java.lang.management.OperatingSystemMXBean"
,
"java.lang.management.OperatingSystemMXBean"
,
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
OperatingSystemMXBean
>()
{
new
MXBeanFetcher
<
OperatingSystemMXBean
>()
{
public
List
<
OperatingSystemMXBean
>
getMXBeans
()
{
public
List
<
OperatingSystemMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getOperatingSystemMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getOperatingSystemMXBean
());
...
@@ -157,6 +164,7 @@ enum PlatformComponent {
...
@@ -157,6 +164,7 @@ enum PlatformComponent {
RUNTIME
(
RUNTIME
(
"java.lang.management.RuntimeMXBean"
,
"java.lang.management.RuntimeMXBean"
,
"java.lang"
,
"Runtime"
,
defaultKeyProperties
(),
"java.lang"
,
"Runtime"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
RuntimeMXBean
>()
{
new
MXBeanFetcher
<
RuntimeMXBean
>()
{
public
List
<
RuntimeMXBean
>
getMXBeans
()
{
public
List
<
RuntimeMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getRuntimeMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getRuntimeMXBean
());
...
@@ -169,6 +177,7 @@ enum PlatformComponent {
...
@@ -169,6 +177,7 @@ enum PlatformComponent {
THREADING
(
THREADING
(
"java.lang.management.ThreadMXBean"
,
"java.lang.management.ThreadMXBean"
,
"java.lang"
,
"Threading"
,
defaultKeyProperties
(),
"java.lang"
,
"Threading"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
ThreadMXBean
>()
{
new
MXBeanFetcher
<
ThreadMXBean
>()
{
public
List
<
ThreadMXBean
>
getMXBeans
()
{
public
List
<
ThreadMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getThreadMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getThreadMXBean
());
...
@@ -180,11 +189,17 @@ enum PlatformComponent {
...
@@ -180,11 +189,17 @@ enum PlatformComponent {
* Logging facility.
* Logging facility.
*/
*/
LOGGING
(
LOGGING
(
"java.
util.logging
.PlatformLoggingMXBean"
,
"java.
lang.management
.PlatformLoggingMXBean"
,
"java.util.logging"
,
"Logging"
,
defaultKeyProperties
(),
"java.util.logging"
,
"Logging"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
PlatformLoggingMXBean
>()
{
new
MXBeanFetcher
<
PlatformLoggingMXBean
>()
{
public
List
<
PlatformLoggingMXBean
>
getMXBeans
()
{
public
List
<
PlatformLoggingMXBean
>
getMXBeans
()
{
return
ManagementFactoryHelper
.
getLoggingMXBean
();
PlatformLoggingMXBean
m
=
ManagementFactoryHelper
.
getPlatformLoggingMXBean
();
if
(
m
==
null
)
{
return
Collections
.
emptyList
();
}
else
{
return
Collections
.
singletonList
(
m
);
}
}
}
}),
}),
...
@@ -192,8 +207,9 @@ enum PlatformComponent {
...
@@ -192,8 +207,9 @@ enum PlatformComponent {
* Buffer pools.
* Buffer pools.
*/
*/
BUFFER_POOL
(
BUFFER_POOL
(
"java.
nio
.BufferPoolMXBean"
,
"java.
lang.management
.BufferPoolMXBean"
,
"java.nio"
,
"BufferPool"
,
keyProperties
(
"name"
),
"java.nio"
,
"BufferPool"
,
keyProperties
(
"name"
),
false
,
// zero or more instances
new
MXBeanFetcher
<
BufferPoolMXBean
>()
{
new
MXBeanFetcher
<
BufferPoolMXBean
>()
{
public
List
<
BufferPoolMXBean
>
getMXBeans
()
{
public
List
<
BufferPoolMXBean
>
getMXBeans
()
{
return
ManagementFactoryHelper
.
getBufferPoolMXBeans
();
return
ManagementFactoryHelper
.
getBufferPoolMXBeans
();
...
@@ -209,6 +225,7 @@ enum PlatformComponent {
...
@@ -209,6 +225,7 @@ enum PlatformComponent {
SUN_GARBAGE_COLLECTOR
(
SUN_GARBAGE_COLLECTOR
(
"com.sun.management.GarbageCollectorMXBean"
,
"com.sun.management.GarbageCollectorMXBean"
,
"java.lang"
,
"GarbageCollector"
,
keyProperties
(
"name"
),
"java.lang"
,
"GarbageCollector"
,
keyProperties
(
"name"
),
false
,
// zero or more instances
new
MXBeanFetcher
<
com
.
sun
.
management
.
GarbageCollectorMXBean
>()
{
new
MXBeanFetcher
<
com
.
sun
.
management
.
GarbageCollectorMXBean
>()
{
public
List
<
com
.
sun
.
management
.
GarbageCollectorMXBean
>
getMXBeans
()
{
public
List
<
com
.
sun
.
management
.
GarbageCollectorMXBean
>
getMXBeans
()
{
return
getGcMXBeanList
(
com
.
sun
.
management
.
GarbageCollectorMXBean
.
class
);
return
getGcMXBeanList
(
com
.
sun
.
management
.
GarbageCollectorMXBean
.
class
);
...
@@ -222,6 +239,7 @@ enum PlatformComponent {
...
@@ -222,6 +239,7 @@ enum PlatformComponent {
SUN_OPERATING_SYSTEM
(
SUN_OPERATING_SYSTEM
(
"com.sun.management.OperatingSystemMXBean"
,
"com.sun.management.OperatingSystemMXBean"
,
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
com
.
sun
.
management
.
OperatingSystemMXBean
>()
{
new
MXBeanFetcher
<
com
.
sun
.
management
.
OperatingSystemMXBean
>()
{
public
List
<
com
.
sun
.
management
.
OperatingSystemMXBean
>
getMXBeans
()
{
public
List
<
com
.
sun
.
management
.
OperatingSystemMXBean
>
getMXBeans
()
{
return
getOSMXBeanList
(
com
.
sun
.
management
.
OperatingSystemMXBean
.
class
);
return
getOSMXBeanList
(
com
.
sun
.
management
.
OperatingSystemMXBean
.
class
);
...
@@ -234,6 +252,7 @@ enum PlatformComponent {
...
@@ -234,6 +252,7 @@ enum PlatformComponent {
SUN_UNIX_OPERATING_SYSTEM
(
SUN_UNIX_OPERATING_SYSTEM
(
"com.sun.management.UnixOperatingSystemMXBean"
,
"com.sun.management.UnixOperatingSystemMXBean"
,
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
"java.lang"
,
"OperatingSystem"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
UnixOperatingSystemMXBean
>()
{
new
MXBeanFetcher
<
UnixOperatingSystemMXBean
>()
{
public
List
<
UnixOperatingSystemMXBean
>
getMXBeans
()
{
public
List
<
UnixOperatingSystemMXBean
>
getMXBeans
()
{
return
getOSMXBeanList
(
com
.
sun
.
management
.
UnixOperatingSystemMXBean
.
class
);
return
getOSMXBeanList
(
com
.
sun
.
management
.
UnixOperatingSystemMXBean
.
class
);
...
@@ -246,6 +265,7 @@ enum PlatformComponent {
...
@@ -246,6 +265,7 @@ enum PlatformComponent {
HOTSPOT_DIAGNOSTIC
(
HOTSPOT_DIAGNOSTIC
(
"com.sun.management.HotSpotDiagnosticMXBean"
,
"com.sun.management.HotSpotDiagnosticMXBean"
,
"com.sun.management"
,
"HotSpotDiagnostic"
,
defaultKeyProperties
(),
"com.sun.management"
,
"HotSpotDiagnostic"
,
defaultKeyProperties
(),
true
,
// singleton
new
MXBeanFetcher
<
HotSpotDiagnosticMXBean
>()
{
new
MXBeanFetcher
<
HotSpotDiagnosticMXBean
>()
{
public
List
<
HotSpotDiagnosticMXBean
>
getMXBeans
()
{
public
List
<
HotSpotDiagnosticMXBean
>
getMXBeans
()
{
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getDiagnosticMXBean
());
return
Collections
.
singletonList
(
ManagementFactoryHelper
.
getDiagnosticMXBean
());
...
@@ -296,27 +316,19 @@ enum PlatformComponent {
...
@@ -296,27 +316,19 @@ enum PlatformComponent {
private
final
Set
<
String
>
keyProperties
;
private
final
Set
<
String
>
keyProperties
;
private
final
MXBeanFetcher
fetcher
;
private
final
MXBeanFetcher
fetcher
;
private
final
PlatformComponent
[]
subComponents
;
private
final
PlatformComponent
[]
subComponents
;
private
final
boolean
singleton
;
private
PlatformComponent
(
String
intfName
,
private
PlatformComponent
(
String
intfName
,
String
domain
,
String
type
,
String
domain
,
String
type
,
Set
<
String
>
keyProperties
,
Set
<
String
>
keyProperties
,
MXBeanFetcher
fetcher
)
{
boolean
singleton
,
this
.
mxbeanInterfaceName
=
intfName
;
this
.
domain
=
domain
;
this
.
type
=
type
;
this
.
keyProperties
=
keyProperties
;
this
.
fetcher
=
fetcher
;
this
.
subComponents
=
new
PlatformComponent
[
0
];
}
private
PlatformComponent
(
String
intfName
,
String
domain
,
String
type
,
Set
<
String
>
keyProperties
,
MXBeanFetcher
fetcher
,
MXBeanFetcher
fetcher
,
PlatformComponent
...
subComponents
)
{
PlatformComponent
...
subComponents
)
{
this
.
mxbeanInterfaceName
=
intfName
;
this
.
mxbeanInterfaceName
=
intfName
;
this
.
domain
=
domain
;
this
.
domain
=
domain
;
this
.
type
=
type
;
this
.
type
=
type
;
this
.
keyProperties
=
keyProperties
;
this
.
keyProperties
=
keyProperties
;
this
.
singleton
=
singleton
;
this
.
fetcher
=
fetcher
;
this
.
fetcher
=
fetcher
;
this
.
subComponents
=
subComponents
;
this
.
subComponents
=
subComponents
;
}
}
...
@@ -338,6 +350,10 @@ enum PlatformComponent {
...
@@ -338,6 +350,10 @@ enum PlatformComponent {
return
set
;
return
set
;
}
}
boolean
isSingleton
()
{
return
singleton
;
}
String
getMXBeanInterfaceName
()
{
String
getMXBeanInterfaceName
()
{
return
mxbeanInterfaceName
;
return
mxbeanInterfaceName
;
}
}
...
@@ -360,6 +376,33 @@ enum PlatformComponent {
...
@@ -360,6 +376,33 @@ enum PlatformComponent {
return
fetcher
.
getMXBeans
();
return
fetcher
.
getMXBeans
();
}
}
<
T
extends
PlatformManagedObject
>
T
getSingletonMXBean
(
Class
<
T
>
mxbeanInterface
)
{
if
(!
singleton
)
throw
new
IllegalArgumentException
(
mxbeanInterfaceName
+
" can have zero or more than one instances"
);
List
<
T
>
list
=
fetcher
.
getMXBeans
();
assert
list
.
size
()
==
1
;
return
list
.
isEmpty
()
?
null
:
list
.
get
(
0
);
}
<
T
extends
PlatformManagedObject
>
T
getSingletonMXBean
(
MBeanServerConnection
mbs
,
Class
<
T
>
mxbeanInterface
)
throws
java
.
io
.
IOException
{
if
(!
singleton
)
throw
new
IllegalArgumentException
(
mxbeanInterfaceName
+
" can have zero or more than one instances"
);
// ObjectName of a singleton MXBean contains only domain and type
assert
keyProperties
.
size
()
==
1
;
String
on
=
domain
+
":type="
+
type
;
return
ManagementFactory
.
newPlatformMXBeanProxy
(
mbs
,
on
,
mxbeanInterface
);
}
<
T
extends
PlatformManagedObject
>
<
T
extends
PlatformManagedObject
>
List
<
T
>
getMXBeans
(
MBeanServerConnection
mbs
,
Class
<
T
>
mxbeanInterface
)
List
<
T
>
getMXBeans
(
MBeanServerConnection
mbs
,
Class
<
T
>
mxbeanInterface
)
throws
java
.
io
.
IOException
throws
java
.
io
.
IOException
...
@@ -391,5 +434,34 @@ enum PlatformComponent {
...
@@ -391,5 +434,34 @@ enum PlatformComponent {
return
set
;
return
set
;
}
}
// a map from MXBean interface name to PlatformComponent
private
static
Map
<
String
,
PlatformComponent
>
enumMap
;
private
static
synchronized
void
ensureInitialized
()
{
if
(
enumMap
==
null
)
{
enumMap
=
new
HashMap
<>();
for
(
PlatformComponent
pc:
PlatformComponent
.
values
())
{
// Use String as the key rather than Class<?> to avoid
// causing unnecessary class loading of management interface
enumMap
.
put
(
pc
.
getMXBeanInterfaceName
(),
pc
);
}
}
}
static
boolean
isPlatformMXBean
(
String
cn
)
{
ensureInitialized
();
return
enumMap
.
containsKey
(
cn
);
}
static
<
T
extends
PlatformManagedObject
>
PlatformComponent
getPlatformComponent
(
Class
<
T
>
mxbeanInterface
)
{
ensureInitialized
();
String
cn
=
mxbeanInterface
.
getName
();
PlatformComponent
pc
=
enumMap
.
get
(
cn
);
if
(
pc
!=
null
&&
pc
.
getMXBeanInterface
()
==
mxbeanInterface
)
return
pc
;
return
null
;
}
private
static
final
long
serialVersionUID
=
6992337162326171013L
;
private
static
final
long
serialVersionUID
=
6992337162326171013L
;
}
}
src/share/classes/java/lang/management/PlatformLoggingMXBean.java
0 → 100644
浏览文件 @
0e37d88a
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
java.lang.management
;
/**
* The management interface for the {@linkplain java.util.logging logging} facility.
*
* <p>There is a single global instance of the <tt>PlatformLoggingMXBean</tt>.
* The {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
* ManagementFactory.getPlatformMXBean} method can be used to obtain
* the {@code PlatformLoggingMXBean} object as follows:
* <pre>
* PlatformLoggingMXBean logging = ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class);
* </pre>
* The {@code PlatformLoggingMXBean} object is also registered with the
* platform {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* MBeanServer}.
* The {@link javax.management.ObjectName ObjectName} for uniquely
* identifying the {@code PlatformLoggingMXBean} within an MBeanServer is:
* <pre>
* {@link java.util.logging.LogManager#LOGGING_MXBEAN_NAME java.util.logging:type=Logging}
* </pre>
*
* <p>The instance registered in the platform <tt>MBeanServer</tt> with
* this {@code ObjectName} implements all attributes defined by
* {@link java.util.logging.LoggingMXBean}.
*
* @since 1.7
*/
public
interface
PlatformLoggingMXBean
extends
PlatformManagedObject
{
/**
* Returns the list of the currently registered
* {@linkplain java.util.logging.Logger logger} names. This method
* calls {@link java.util.logging.LogManager#getLoggerNames} and
* returns a list of the logger names.
*
* @return A list of {@code String} each of which is a
* currently registered {@code Logger} name.
*/
java
.
util
.
List
<
String
>
getLoggerNames
();
/**
* Gets the name of the log {@linkplain java.util.logging.Logger#getLevel
* level} associated with the specified logger.
* If the specified logger does not exist, {@code null}
* is returned.
* This method first finds the logger of the given name and
* then returns the name of the log level by calling:
* <blockquote>
* {@link java.util.logging.Logger#getLevel
* Logger.getLevel()}.{@link java.util.logging.Level#getName getName()};
* </blockquote>
*
* <p>
* If the {@code Level} of the specified logger is {@code null},
* which means that this logger's effective level is inherited
* from its parent, an empty string will be returned.
*
* @param loggerName The name of the {@code Logger} to be retrieved.
*
* @return The name of the log level of the specified logger; or
* an empty string if the log level of the specified logger
* is {@code null}. If the specified logger does not
* exist, {@code null} is returned.
*
* @see java.util.logging.Logger#getLevel
*/
String
getLoggerLevel
(
String
loggerName
);
/**
* Sets the specified logger to the specified new
* {@linkplain java.util.logging.Logger#setLevel level}.
* If the {@code levelName} is not {@code null}, the level
* of the specified logger is set to the parsed
* {@link java.util.logging.Level Level}
* matching the {@code levelName}.
* If the {@code levelName} is {@code null}, the level
* of the specified logger is set to {@code null} and
* the effective level of the logger is inherited from
* its nearest ancestor with a specific (non-null) level value.
*
* @param loggerName The name of the {@code Logger} to be set.
* Must be non-null.
* @param levelName The name of the level to set on the specified logger,
* or {@code null} if setting the level to inherit
* from its nearest ancestor.
*
* @throws IllegalArgumentException if the specified logger
* does not exist, or {@code levelName} is not a valid level name.
*
* @throws SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
*
* @see java.util.logging.Logger#setLevel
*/
void
setLoggerLevel
(
String
loggerName
,
String
levelName
);
/**
* Returns the name of the
* {@linkplain java.util.logging.Logger#getParent parent}
* for the specified logger.
* If the specified logger does not exist, {@code null} is returned.
* If the specified logger is the root {@code Logger} in the namespace,
* the result will be an empty string.
*
* @param loggerName The name of a {@code Logger}.
*
* @return the name of the nearest existing parent logger;
* an empty string if the specified logger is the root logger.
* If the specified logger does not exist, {@code null}
* is returned.
*/
String
getParentLoggerName
(
String
loggerName
);
}
src/share/classes/java/lang/management/PlatformManagedObject.java
浏览文件 @
0e37d88a
...
@@ -46,7 +46,7 @@ import javax.management.ObjectName;
...
@@ -46,7 +46,7 @@ import javax.management.ObjectName;
* intended for the management interfaces for the platform to extend but
* intended for the management interfaces for the platform to extend but
* not for applications.
* not for applications.
*
*
* @see
<a href="ManagementFactory.html#MXBean">Platform MXBeans</a>
* @see
ManagementFactory
* @since 1.7
* @since 1.7
*/
*/
public
interface
PlatformManagedObject
{
public
interface
PlatformManagedObject
{
...
...
src/share/classes/java/lang/management/package.html
浏览文件 @
0e37d88a
...
@@ -27,108 +27,24 @@
...
@@ -27,108 +27,24 @@
<html>
<html>
<body
bgcolor=
"white"
>
<body
bgcolor=
"white"
>
Provides the management interface
for monitoring and management of the
Provides the management interface
s for monitoring and management of the
Java virtual machine a
s well as the operating system on which the
Java virtual machine a
nd other components in the Java runtime.
Java virtual machine is running. It allows both local and remote
It allows both local and remote
monitoring and management of the running Java virtual machine.
monitoring and management of the running Java virtual machine.
<h4>
Platform MXBeans
</h4>
This package defines the management interface of the following
components:
<blockquote>
<table
cellspacing=
1
summary=
"Description of the MBeans"
>
<tr>
<th><p
align=
"left"
>
Management Interface
</p></th>
<th><p
align=
"left"
>
Description
</p></th>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.ClassLoadingMXBean}
</tt>
</td>
<td>
Class loading system of the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.CompilationMXBean}
</tt>
</td>
<td>
Compilation system of the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.MemoryMXBean}
</tt>
</td>
<td>
Memory system of the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.ThreadMXBean}
</tt>
</td>
<td>
Threads system of the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.RuntimeMXBean}
</tt>
</td>
<td>
Runtime system of the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.OperatingSystemMXBean}
</tt>
</td>
<td>
Operating system on which the Java virtual machine is running.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.GarbageCollectorMXBean}
</tt>
</td>
<td>
Garbage collector in the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.MemoryManagerMXBean}
</tt>
</td>
<td>
Memory manager in the Java virtual machine.
</td>
</tr>
<tr>
<td>
<tt>
{@link java.lang.management.MemoryPoolMXBean}
</tt>
</td>
<td>
Memory pool in the Java virtual machine.
</td>
</tr>
</table>
</blockquote>
<p>
<p>
A platform MXBean is a
<i>
managed bean
</i>
that defines the management
interface for one component for the platform and is specified in the
<a
href=
"ManagementFactory.html#MXBean"
>
ManagementFactory
</a>
class.
<p>
An application can monitor the instrumentation of the
Java virtual machine and manage certain characteristics in
the following ways:
<ul>
<li><i>
Direct access to an MXBean interface
</i>
<ol
type=
"a"
>
<li>
Get the MXBean instance through the static factory method
and access the MXBean interface locally of the running
virtual machine.
</li>
<li>
Construct an MXBean proxy instance that
forwards the method calls to a given
{@link javax.management.MBeanServer MBeanServer}
by calling
{@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
ManagementFactory.newPlatformMXBeanProxy}.
A proxy is typically constructed to remotely access
an MXBean of another running virtual machine.
</li>
</ol></li>
<li><i>
Indirect access via {@link javax.management.MBeanServer MBeanServer}
interface
</i>
<ol
type=
"a"
>
<li>
Go through the
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
platform MBeanServer} to access MXBeans locally or
a specific
<tt>
MBeanServerConnection
</tt>
to access
MXBeans remotely.
The attributes and operations of an MXBean use only
<em>
JMX open types
</em>
which include basic data types,
{@link javax.management.openmbean.CompositeData CompositeData},
and {@link javax.management.openmbean.TabularData TabularData}
defined in {@link javax.management.openmbean.OpenType OpenType}.
</li>
</ol></li>
</ul>
Below shows a few
<a
href=
"#examples"
>
examples
</a>
of different
ways to access MXBeans.
<h4><a
name=
"MXBean"
>
Platform MXBean
</a></h4>
<p>
A platform MXBean is a
<i>
managed bean
</i>
that
conforms to the
<a
href=
"../../../javax/management/package-summary.html"
>
JMX
</a>
Instrumentation Specification and only uses a set of basic data types.
Each platform MXBean is a {@link java.lang.management.PlatformManagedObject}
with a unique
{@linkplain java.lang.management.PlatformManagedObject#getObjectName name}.
<p>
<h4>
ManagementFactory
</h4>
<h4>
ManagementFactory
</h4>
The {@link java.lang.management.ManagementFactory} class is the management
<p>
The {@link java.lang.management.ManagementFactory} class is the management
factory class for the Java platform. This class provides a set of
factory class for the Java platform. This class provides a set of
static factory methods to obtain the MXBeans for the Java platform
static factory methods to obtain the MXBeans for the Java platform
to allow an application to access the MXBeans directly.
to allow an application to access the MXBeans directly.
...
@@ -137,50 +53,98 @@ to allow an application to access the MXBeans directly.
...
@@ -137,50 +53,98 @@ to allow an application to access the MXBeans directly.
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
getPlatformMBeanServer} method. On the first call to this method,
getPlatformMBeanServer} method. On the first call to this method,
it creates the platform MBeanServer and registers all platform MXBeans
it creates the platform MBeanServer and registers all platform MXBeans
including platform MXBeans defined in other packages such as
including {@linkplain java.lang.management.PlatformManagedObject
{@link java.util.logging.LoggingMXBean}.
platform MXBeans}.
Each platform MXBean is registered with a unique name defined in the
Each platform MXBean is registered with a unique name defined in
{@link java.lang.management.ManagementFactory ManagementFactory} class
the specification of the management interface.
for constructing {@link javax.management.ObjectName ObjectName}.
This is a single MBeanServer that can be shared by different managed
This is a single MBeanServer that can be shared by different managed
components running within the same Java virtual machine.
components running within the same Java virtual machine.
<h4>
Interoperability
</h4>
<h4>
Interoperability
</h4>
A management application and a platform MBeanServer of a running
<p>
A management application and a platform MBeanServer of a running
virtual machine can interoperate
virtual machine can interoperate
without requiring classes used by the platform MXBean interfaces.
without requiring classes used by the platform MXBean interfaces.
The data types being transmitted between the JMX connector
The data types being transmitted between the JMX connector
server and the connector client are JMX
server and the connector client are JMX
{@link javax.management.openmbean.OpenType open types} and
{@link
plain
javax.management.openmbean.OpenType open types} and
this allows interoperation across versions.
this allows interoperation across versions.
A data type used by the MXBean interfaces are mapped to an
<p>
A data type used by the MXBean interfaces are mapped to
open type when being accessed via MBeanServer interface.
an open type when being accessed via MBeanServer interface.
See the
<a
href=
"../../../javax/management/MXBean.html#MXBean-spec"
>
The data type mapping is specified in the
MXBean
</a>
specification for details.
{@link java.lang.management.ManagementFactory ManagementFactory} class.
<h4><a
name=
"examples"
>
Ways to Access MXBeans
</a></h4>
<h4><a
name=
"examples"
>
Ways to Access MXBeans
</a></h4>
There are three different ways to access the management interfaces.
<p>
An application can monitor the instrumentation of the
Java virtual machine and the runtime in the following ways:
<p>
<p>
<ol>
<b>
1. Direct access to an MXBean interface
</b>
<li>
Call the methods in the MXBean directly within the same
<p>
Java virtual machine.
<ul>
<blockquote><pre>
<li>
Get an MXBean instance locally in the running Java virtual machine:
<p>
<pre>
RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
// Get the standard attribute "VmVendor"
// Get the standard attribute "VmVendor"
String vendor = mxbean.getVmVendor();
String vendor = mxbean.getVmVendor();
</pre>
<p>
Or by calling the
{@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
getPlatformMXBean} or
{@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
getPlatformMXBeans} method:
<pre>
RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);
// Get the standard attribute "VmVendor"
String vendor = mxbean.getVmVendor();
</pre>
</pre>
<
/blockquote
>
<
p
>
</li>
</li>
<li>
Construct an MXBean proxy instance that forwards the
method calls to a given MBeanServer:
<p>
<pre>
MBeanServerConnection mbs;
<li>
Go through a
<tt>
MBeanServerConnection
</tt>
connecting
// Connect to a running JVM (or itself) and get MBeanServerConnection
to the
<tt>
platform MBeanServer
</tt>
of a running virtual machine.
</li>
// that has the JVM MBeans registered in it
<blockquote><pre>
...
// Get a MBean proxy for RuntimeMXBean interface
RuntimeMXBean proxy =
{@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class)
ManagementFactory.getPlatformMXBean}(mbs,
RuntimeMXBean.class);
// Get standard attribute "VmVendor"
String vendor = proxy.getVmVendor();
</pre>
<p>
A proxy is typically used to access an MXBean
in a remote Java virtual machine.
An alternative way to create an MXBean proxy is:
<pre>
RuntimeMXBean proxy =
{@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
ManagementFactory.newPlatformMXBeanProxy}(mbs,
ManagementFactory.RUNTIME_MXBEAN_NAME,
RuntimeMXBean.class);
</pre>
</li>
</ul>
<p>
<b>
2. Indirect access to an MXBean interface via MBeanServer
</b><p>
<ul>
<li>
Go through the
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
platform MBeanServer} to access MXBeans locally or
a specific {@code MBeanServerConnection} to access
MXBeans remotely.
The attributes and operations of an MXBean use only
<em>
JMX open types
</em>
which include basic data types,
{@link javax.management.openmbean.CompositeData CompositeData},
and {@link javax.management.openmbean.TabularData TabularData}
defined in {@link javax.management.openmbean.OpenType OpenType}.
<p>
<pre>
MBeanServerConnection mbs;
MBeanServerConnection mbs;
// Connect to a running JVM (or itself) and get MBeanServerConnection
// Connect to a running JVM (or itself) and get MBeanServerConnection
...
@@ -198,36 +162,19 @@ There are three different ways to access the management interfaces.
...
@@ -198,36 +162,19 @@ There are three different ways to access the management interfaces.
// and MBeanServer.getAttribute method
// and MBeanServer.getAttribute method
...
...
}
}
</pre>
</pre></blockquote>
</li>
</ul>
<li>
Use MXBean proxy.
</li>
<blockquote><pre>
MBeanServerConnection mbs;
// Connect to a running JVM (or itself) and get MBeanServerConnection
// that has the JVM MBeans registered in it
...
// Get a MBean proxy for RuntimeMXBean interface
RuntimeMXBean proxy =
ManagementFactory.newPlatformMXBeanProxy(mbs,
ManagementFactory.RUNTIME_MXBEAN_NAME,
RuntimeMXBean.class);
// Get standard attribute "VmVendor"
String vendor = proxy.getVmVendor();
</pre></blockquote>
</ol>
<h4><a
name=
"extension"
>
Platform Extension
</a></h4>
<h4><a
name=
"extension"
>
Platform Extension
</a></h4>
A Java virtual machine implementation may add its platform extension to
<p>
A Java virtual machine implementation may add its platform extension to
the management interface by defining platform-dependent
the management interface by defining platform-dependent
interfaces that extend the standard management interfaces to include
interfaces that extend the standard management interfaces to include
platform-specific metrics and management operations.
platform-specific metrics and management operations.
The static factory methods in the
<tt>
ManagementFactory
</tt>
class will
The static factory methods in the
<tt>
ManagementFactory
</tt>
class will
return the MBeans with the platform extension.
return the M
X
Beans with the platform extension.
<p>
<p>
It is recommended to name the platform-specific attributes with
It is recommended to name the platform-specific attributes with
...
@@ -240,26 +187,30 @@ is happened to be same as some vendor-specific attribute's name,
...
@@ -240,26 +187,30 @@ is happened to be same as some vendor-specific attribute's name,
the applications accessing that vendor-specific attribute would have
the applications accessing that vendor-specific attribute would have
to be modified to cope with versioning and compatibility issues.
to be modified to cope with versioning and compatibility issues.
<p>
Below is an example showing how to access a
platform-specific
<p>
Below is an example showing how to access a
n attribute
attribute from Sun's implementation of the
<tt>
RuntimeMXBean
</tt>
.
from the platform extension:
<p>
<p>
1) Direct access to the Sun-specific MXBean interface
1) Direct access to the Oracle-specific MXBean interface
<blockquote><pre>
<blockquote>
com.sun.management.RuntimeMXBean mxbean =
<pre>
(com.sun.management.RuntimeMXBean) ManagementFactory.getRuntimeMXBean();
List
<
com.sun.management.GarbageCollectorMXBean
>
mxbeans =
ManagementFactory.getPlatformMXBeans(com.sun.management.GarbageCollectorMXBean.class);
// Get the standard attribute "VmVendor"
String vendor = mxbean.getVmVendor();
// Get the platform-specific attribute "Bar"
for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
BarType bar = mxbean.getBar();
// Get the standard attribute "CollectionCount"
String count = mxbean.getCollectionCount();
// Get the platform-specific attribute "LastGcInfo"
GcInfo gcinfo = gc.getLastGcInfo();
...
}
</pre>
</pre>
</blockquote>
</blockquote>
<p>
<p>
2) Access the Sun-specific MXBean interface via
<tt>
MBeanServer
</tt>
2) Access the Oracle-specific MXBean interface via
<tt>
MBeanServer
</tt>
through proxy
<blockquote><pre>
<blockquote><pre>
MBeanServerConnection mbs;
MBeanServerConnection mbs;
...
@@ -268,24 +219,17 @@ attribute from Sun's implementation of the <tt>RuntimeMXBean</tt>.
...
@@ -268,24 +219,17 @@ attribute from Sun's implementation of the <tt>RuntimeMXBean</tt>.
// that has the JVM MXBeans registered in it
// that has the JVM MXBeans registered in it
...
...
try {
List
<
com.sun.management.GarbageCollectorMXBean
>
mxbeans =
// Assuming the RuntimeMXBean has been registered in mbs
ManagementFactory.getPlatformMXBeans(mbs, com.sun.management.GarbageCollectorMXBean.class);
ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
// Get standard attribute "VmVendor"
for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
String vendor = (String) mbs.getAttribute(oname, "VmVendor");
// Get the standard attribute "CollectionCount"
String count = mxbean.getCollectionCount();
// Check if this MXBean contains Sun's extension
// Get the platform-specific attribute "LastGcInfo"
if (mbs.isInstanceOf(oname, "com.sun.management.RuntimeMXBean")) {
GcInfo gcinfo = gc.getLastGcInfo();
// Get platform-specific attribute "Bar"
BarType bar = (String) mbs.getAttribute(oname, "Bar");
}
} catch (....) {
// Catch the exceptions thrown by ObjectName constructor
// and MBeanServer methods
...
...
}
}
</pre></blockquote>
</pre></blockquote>
<p>
Unless otherwise noted, passing a
<tt>
null
</tt>
argument to a constructor
<p>
Unless otherwise noted, passing a
<tt>
null
</tt>
argument to a constructor
...
...
src/share/classes/java/util/logging/LogManager.java
浏览文件 @
0e37d88a
...
@@ -1166,7 +1166,12 @@ public class LogManager {
...
@@ -1166,7 +1166,12 @@ public class LogManager {
private
static
LoggingMXBean
loggingMXBean
=
null
;
private
static
LoggingMXBean
loggingMXBean
=
null
;
/**
/**
* String representation of the
* String representation of the
* {@link javax.management.ObjectName} for {@link LoggingMXBean}.
* {@link javax.management.ObjectName} for the management interface
* for the logging facility.
*
* @see java.lang.management.PlatformLoggingMXBean
* @see java.util.logging.LoggingMXBean
*
* @since 1.5
* @since 1.5
*/
*/
public
final
static
String
LOGGING_MXBEAN_NAME
public
final
static
String
LOGGING_MXBEAN_NAME
...
@@ -1174,17 +1179,17 @@ public class LogManager {
...
@@ -1174,17 +1179,17 @@ public class LogManager {
/**
/**
* Returns <tt>LoggingMXBean</tt> for managing loggers.
* Returns <tt>LoggingMXBean</tt> for managing loggers.
* An alternative way to manage loggers is
using
* An alternative way to manage loggers is
through the
*
the {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
*
{@link java.lang.management.PlatformLoggingMXBean} interface
*
ManagementFactory.getPlatformMXBeans} method as follows
:
*
that can be obtained by calling
:
* <pre>
* <pre>
* List<{@link PlatformLoggingMXBean}> result = ManagementFactory.getPlatformMXBeans(PlatformLoggingMXBean.class);
* PlatformLoggingMXBean logging = {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
* ManagementFactory.getPlatformMXBean}(PlatformLoggingMXBean.class);
* </pre>
* </pre>
*
*
* @return a {@link LoggingMXBean} object.
* @return a {@link LoggingMXBean} object.
*
*
* @see PlatformLoggingMXBean
* @see java.lang.management.PlatformLoggingMXBean
* @see java.lang.management.ManagementFactory
* @since 1.5
* @since 1.5
*/
*/
public
static
synchronized
LoggingMXBean
getLoggingMXBean
()
{
public
static
synchronized
LoggingMXBean
getLoggingMXBean
()
{
...
...
src/share/classes/java/util/logging/LoggingMXBean.java
浏览文件 @
0e37d88a
...
@@ -27,36 +27,41 @@ package java.util.logging;
...
@@ -27,36 +27,41 @@ package java.util.logging;
/**
/**
* The management interface for the logging facility.
* The management interface for the logging facility. It is recommended
* to use the {@link java.lang.management.PlatformLoggingMXBean} management
* interface that implements all attributes defined in this
* {@code LoggingMXBean}. The
* {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
* ManagementFactory.getPlatformMXBean} method can be used to obtain
* the {@code PlatformLoggingMXBean} object representing the management
* interface for logging.
*
*
* <p>There is a single global instance of the <tt>LoggingMXBean</tt>.
* <p>There is a single global instance of the <tt>LoggingMXBean</tt>.
* This instance is an
* This instance is an {@link javax.management.MXBean MXBean} that
* <a href="../../lang/management/ManagementFactory.html#MXBean">MXBean</a>
* can be obtained by calling the {@link LogManager#getLoggingMXBean}
* can be obtained by calling
* method or from the
* the {@link LogManager#getLoggingMXBean} method or from the
* {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>}.
* platform <tt>MBeanServer</tt>}.
*
* <p>
* The {@link javax.management.ObjectName ObjectName} for uniquely
* The {@link javax.management.ObjectName ObjectName} that uniquely identifies
* identifying the <tt>LoggingMXBean</tt> within an MBeanServer is:
* the management interface for logging within the {@code MBeanServer} is:
* <blockquote>
* <pre>
* {@link LogManager#LOGGING_MXBEAN_NAME
* {@link LogManager#LOGGING_MXBEAN_NAME java.util.logging:type=Logging}
* <tt>java.util.logging:type=Logging</tt>}
* </pre>
* </blockquote>
* <p>
*
* The instance registered in the platform {@code MBeanServer}
* The instance registered in the platform <tt>MBeanServer</tt> with
* is also a {@link java.lang.management.PlatformLoggingMXBean}.
* this {@code ObjectName} is also a {@link PlatformLoggingMXBean}.
*
*
* @author Ron Mann
* @author Ron Mann
* @author Mandy Chung
* @author Mandy Chung
* @since 1.5
* @since 1.5
*
*
* @see PlatformLoggingMXBean
* @see
java.lang.management.
PlatformLoggingMXBean
*/
*/
public
interface
LoggingMXBean
{
public
interface
LoggingMXBean
{
/**
/**
* Returns the list of currently registered loggers. This method
* Returns the list of currently registered logger
name
s. This method
* calls {@link LogManager#getLoggerNames} and returns a list
* calls {@link LogManager#getLoggerNames} and returns a list
* of the logger names.
* of the logger names.
*
*
...
@@ -89,7 +94,7 @@ public interface LoggingMXBean {
...
@@ -89,7 +94,7 @@ public interface LoggingMXBean {
*
*
* @see Logger#getLevel
* @see Logger#getLevel
*/
*/
public
String
getLoggerLevel
(
String
loggerName
);
public
String
getLoggerLevel
(
String
loggerName
);
/**
/**
* Sets the specified logger to the specified new level.
* Sets the specified logger to the specified new level.
...
@@ -115,7 +120,7 @@ public interface LoggingMXBean {
...
@@ -115,7 +120,7 @@ public interface LoggingMXBean {
*
*
* @see Logger#setLevel
* @see Logger#setLevel
*/
*/
public
void
setLoggerLevel
(
String
loggerName
,
String
levelName
);
public
void
setLoggerLevel
(
String
loggerName
,
String
levelName
);
/**
/**
* Returns the name of the parent for the specified logger.
* Returns the name of the parent for the specified logger.
...
...
src/share/classes/java/util/logging/PlatformLoggingMXBean.java
已删除
100644 → 0
浏览文件 @
7254cc99
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
java.util.logging
;
import
java.lang.management.PlatformManagedObject
;
/**
* The {@linkplain PlatformManagedObject platform managed object} for the
* logging facility. This interface simply unifies {@link LoggingMXBean}
* {@link PlatformManagedObject};
* and it does not specify any new operations.
*
* <p>The {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
* ManagementFactory.getPlatformMXBeans} method can be used to obtain
* the {@code PlatformLoggingMXBean} object as follows:
* <pre>
* ManagementFactory.getPlatformMXBeans(PlatformLoggingMXBean.class);
* </pre>
* or from the {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>}.
*
* The {@link javax.management.ObjectName ObjectName} for uniquely
* identifying the <tt>LoggingMXBean</tt> within an MBeanServer is:
* <blockquote>
* <tt>java.util.logging:type=Logging</tt>
* </blockquote>
*
* The {@link PlatformManagedObject#getObjectName} method
* can be used to obtain its {@code ObjectName}.
*
* @see java.lang.management.PlatformManagedObject
*
* @author Mandy Chung
* @since 1.7
*/
public
interface
PlatformLoggingMXBean
extends
LoggingMXBean
,
PlatformManagedObject
{
}
src/share/classes/sun/management/ManagementFactoryHelper.java
浏览文件 @
0e37d88a
...
@@ -27,20 +27,18 @@ package sun.management;
...
@@ -27,20 +27,18 @@ package sun.management;
import
java.lang.management.*
;
import
java.lang.management.*
;
import
javax.management.MBeanServer
;
import
javax.management.ObjectName
;
import
javax.management.InstanceAlreadyExistsException
;
import
javax.management.InstanceAlreadyExistsException
;
import
javax.management.InstanceNotFoundException
;
import
javax.management.InstanceNotFoundException
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanRegistrationException
;
import
javax.management.MBeanRegistrationException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.RuntimeOperationsException
;
import
javax.management.RuntimeOperationsException
;
import
java.nio.BufferPoolMXBean
;
import
java.security.AccessController
;
import
java.security.AccessController
;
import
java.security.PrivilegedActionException
;
import
java.security.PrivilegedActionException
;
import
java.security.PrivilegedExceptionAction
;
import
java.security.PrivilegedExceptionAction
;
import
sun.security.action.LoadLibraryAction
;
import
sun.security.action.LoadLibraryAction
;
import
java.util.logging.PlatformLoggingMXBean
;
import
sun.util.logging.LoggingSupport
;
import
sun.util.logging.LoggingSupport
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -139,17 +137,34 @@ public class ManagementFactoryHelper {
...
@@ -139,17 +137,34 @@ public class ManagementFactoryHelper {
return
result
;
return
result
;
}
}
public
static
List
<
PlatformLoggingMXBean
>
get
LoggingMXBean
()
{
public
static
PlatformLoggingMXBean
getPlatform
LoggingMXBean
()
{
if
(
LoggingSupport
.
isAvailable
())
{
if
(
LoggingSupport
.
isAvailable
())
{
return
Collections
.
singletonList
(
createPlatformLoggingMXBean
())
;
return
PlatformLoggingImpl
.
instance
;
}
else
{
}
else
{
return
Collections
.
emptyList
()
;
return
null
;
}
}
}
}
private
final
static
String
LOGGING_MXBEAN_NAME
=
"java.util.logging:type=Logging"
;
// The logging MXBean object is an instance of
private
static
PlatformLoggingMXBean
createPlatformLoggingMXBean
()
{
// PlatformLoggingMXBean and java.util.logging.LoggingMXBean
return
new
PlatformLoggingMXBean
()
{
// but it can't directly implement two MXBean interfaces
// as a compliant MXBean implements exactly one MXBean interface,
// or if it implements one interface that is a subinterface of
// all the others; otherwise, it is a non-compliant MXBean
// and MBeanServer will throw NotCompliantMBeanException.
// See the Definition of an MXBean section in javax.management.MXBean spec.
//
// To create a compliant logging MXBean, define a LoggingMXBean interface
// that extend PlatformLoggingMXBean and j.u.l.LoggingMXBean
interface
LoggingMXBean
extends
PlatformLoggingMXBean
,
java
.
util
.
logging
.
LoggingMXBean
{
}
static
class
PlatformLoggingImpl
implements
LoggingMXBean
{
final
static
PlatformLoggingMXBean
instance
=
new
PlatformLoggingImpl
();
final
static
String
LOGGING_MXBEAN_NAME
=
"java.util.logging:type=Logging"
;
private
volatile
ObjectName
objname
;
// created lazily
private
volatile
ObjectName
objname
;
// created lazily
@Override
@Override
public
ObjectName
getObjectName
()
{
public
ObjectName
getObjectName
()
{
...
@@ -184,16 +199,18 @@ public class ManagementFactoryHelper {
...
@@ -184,16 +199,18 @@ public class ManagementFactoryHelper {
public
String
getParentLoggerName
(
String
loggerName
)
{
public
String
getParentLoggerName
(
String
loggerName
)
{
return
LoggingSupport
.
getParentLoggerName
(
loggerName
);
return
LoggingSupport
.
getParentLoggerName
(
loggerName
);
}
}
};
}
}
public
static
List
<
BufferPoolMXBean
>
getBufferPoolMXBeans
()
{
private
static
List
<
BufferPoolMXBean
>
bufferPools
=
null
;
List
<
BufferPoolMXBean
>
pools
=
new
ArrayList
<
BufferPoolMXBean
>(
2
);
public
static
synchronized
List
<
BufferPoolMXBean
>
getBufferPoolMXBeans
()
{
pools
.
add
(
createBufferPoolMXBean
(
sun
.
misc
.
SharedSecrets
.
getJavaNioAccess
()
if
(
bufferPools
==
null
)
{
bufferPools
=
new
ArrayList
<>(
2
);
bufferPools
.
add
(
createBufferPoolMXBean
(
sun
.
misc
.
SharedSecrets
.
getJavaNioAccess
()
.
getDirectBufferPool
()));
.
getDirectBufferPool
()));
p
ools
.
add
(
createBufferPoolMXBean
(
sun
.
nio
.
ch
.
FileChannelImpl
bufferP
ools
.
add
(
createBufferPoolMXBean
(
sun
.
nio
.
ch
.
FileChannelImpl
.
getMappedBufferPool
()));
.
getMappedBufferPool
()));
return
pools
;
}
return
bufferPools
;
}
}
private
final
static
String
BUFFER_POOL_MXBEAN_NAME
=
"java.nio:type=BufferPool"
;
private
final
static
String
BUFFER_POOL_MXBEAN_NAME
=
"java.nio:type=BufferPool"
;
...
...
test/Makefile
浏览文件 @
0e37d88a
...
@@ -504,7 +504,7 @@ jdk_nio1: $(call TestDirs, java/nio/file)
...
@@ -504,7 +504,7 @@ jdk_nio1: $(call TestDirs, java/nio/file)
# Stable samevm testruns (minus items from PROBLEM_LIST)
# Stable samevm testruns (minus items from PROBLEM_LIST)
JDK_ALL_TARGETS
+=
jdk_nio2
JDK_ALL_TARGETS
+=
jdk_nio2
jdk_nio2
:
$(call TestDirs
,
java/nio/Buffer java/nio/ByteOrder
\
jdk_nio2
:
$(call TestDirs
,
java/nio/Buffer java/nio/ByteOrder
\
java/nio/channels java/nio/
BufferPoolMXBean java/nio/
MappedByteBuffer)
java/nio/channels java/nio/MappedByteBuffer)
$(
call
SharedLibraryPermissions,java/nio/channels
)
$(
call
SharedLibraryPermissions,java/nio/channels
)
$(
call
RunSamevmBatch
)
$(
call
RunSamevmBatch
)
...
...
test/java/
nio
/BufferPoolMXBean/Basic.java
→
test/java/
lang/management
/BufferPoolMXBean/Basic.java
浏览文件 @
0e37d88a
...
@@ -22,20 +22,22 @@
...
@@ -22,20 +22,22 @@
*/
*/
/* @test
/* @test
* @bug 6606598
* @bug 6606598
7024172
* @summary Unit test for java.
nio
.BufferPoolMXBean
* @summary Unit test for java.
lang.management
.BufferPoolMXBean
* @run main/othervm Basic
* @run main/othervm Basic
*/
*/
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.MappedByteBuffer
;
import
java.nio.MappedByteBuffer
;
import
java.nio.BufferPoolMXBean
;
import
java.nio.file.Path
;
import
java.nio.file.Files
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.*;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileChannel
;
import
java.io.File
;
import
java.lang.management.BufferPoolMXBean
;
import
java.io.RandomAccessFile
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.ManagementFactory
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServer
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
java.lang.ref.WeakReference
;
import
java.util.*
;
import
java.util.*
;
public
class
Basic
{
public
class
Basic
{
...
@@ -78,21 +80,21 @@ public class Basic {
...
@@ -78,21 +80,21 @@ public class Basic {
totalCapacity
+=
cap
;
totalCapacity
+=
cap
;
}
}
// map a file
// create a mapped buffer
File
f
=
File
.
createTempFile
(
"blah"
,
null
);
Path
tmpfile
=
Files
.
createTempFile
(
"blah"
,
null
);
f
.
deleteOnExit
();
tmpfile
.
toFile
().
deleteOnExit
();
RandomAccessFile
raf
=
new
RandomAccessFile
(
f
,
"rw"
);
try
(
FileChannel
fc
=
FileChannel
.
open
(
tmpfile
,
READ
,
WRITE
))
{
FileChannel
fc
=
raf
.
getChannel
();
mbb
=
fc
.
map
(
FileChannel
.
MapMode
.
READ_WRITE
,
10
,
100
);
mbb
=
fc
.
map
(
FileChannel
.
MapMode
.
READ_WRITE
,
10
,
100
);
bufferCount
++;
bufferCount
++;
totalCapacity
+=
mbb
.
capacity
();
totalCapacity
+=
mbb
.
capacity
();
}
//
direct
//
use platform MXBeans directly
List
<
BufferPoolMXBean
>
pools
=
List
<
BufferPoolMXBean
>
pools
=
ManagementFactory
.
getPlatformMXBeans
(
BufferPoolMXBean
.
class
);
ManagementFactory
.
getPlatformMXBeans
(
BufferPoolMXBean
.
class
);
check
(
pools
,
bufferCount
,
totalCapacity
);
check
(
pools
,
bufferCount
,
totalCapacity
);
// us
ing
MBeanServer
// us
e
MBeanServer
MBeanServer
server
=
ManagementFactory
.
getPlatformMBeanServer
();
MBeanServer
server
=
ManagementFactory
.
getPlatformMBeanServer
();
Set
<
ObjectName
>
mbeans
=
server
.
queryNames
(
Set
<
ObjectName
>
mbeans
=
server
.
queryNames
(
new
ObjectName
(
"java.nio:type=BufferPool,*"
),
null
);
new
ObjectName
(
"java.nio:type=BufferPool,*"
),
null
);
...
@@ -103,5 +105,13 @@ public class Basic {
...
@@ -103,5 +105,13 @@ public class Basic {
pools
.
add
(
pool
);
pools
.
add
(
pool
);
}
}
check
(
pools
,
bufferCount
,
totalCapacity
);
check
(
pools
,
bufferCount
,
totalCapacity
);
// attempt to unmap mapped buffer
WeakReference
<
MappedByteBuffer
>
ref
=
new
WeakReference
<>(
mbb
);
mbb
=
null
;
do
{
System
.
gc
();
Thread
.
sleep
(
250
);
}
while
(
ref
.
get
()
!=
null
);
}
}
}
}
test/java/lang/management/ManagementFactory/GetPlatformMXBeans.java
浏览文件 @
0e37d88a
...
@@ -23,23 +23,26 @@
...
@@ -23,23 +23,26 @@
/*
/*
* @test
* @test
* @bug 6610094
* @bug 6610094
7024172
* @summary Basic unit test of ManagementFactory.getPlatformMXBean
s(
)
* @summary Basic unit test of ManagementFactory.getPlatformMXBean
(s
)
*
and also
PlatformManagedObject.getObjectName()
*
methods and
PlatformManagedObject.getObjectName()
* @author Mandy Chung
* @author Mandy Chung
*
*
* @run main GetPlatformMXBeans
* @run main GetPlatformMXBeans
*/
*/
import
java.lang.management.*
;
import
java.lang.management.*
;
import
static
java
.
lang
.
management
.
ManagementFactory
.*
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.*
;
import
javax.management.*
;
import
javax.management.*
;
import
static
java
.
lang
.
management
.
ManagementFactory
.*;
public
class
GetPlatformMXBeans
{
public
class
GetPlatformMXBeans
{
private
static
MBeanServer
platformMBeanServer
=
private
static
MBeanServer
platformMBeanServer
=
getPlatformMBeanServer
();
getPlatformMBeanServer
();
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
// singleton platform MXBean
checkPlatformMXBean
(
getClassLoadingMXBean
(),
checkPlatformMXBean
(
getClassLoadingMXBean
(),
ClassLoadingMXBean
.
class
,
ClassLoadingMXBean
.
class
,
CLASS_LOADING_MXBEAN_NAME
);
CLASS_LOADING_MXBEAN_NAME
);
...
@@ -58,17 +61,28 @@ public class GetPlatformMXBeans {
...
@@ -58,17 +61,28 @@ public class GetPlatformMXBeans {
checkPlatformMXBean
(
getThreadMXBean
(),
checkPlatformMXBean
(
getThreadMXBean
(),
ThreadMXBean
.
class
,
ThreadMXBean
.
class
,
THREAD_MXBEAN_NAME
);
THREAD_MXBEAN_NAME
);
// the following MXBean can have more than one instances
checkGarbageCollectorMXBeans
(
getGarbageCollectorMXBeans
());
checkGarbageCollectorMXBeans
(
getGarbageCollectorMXBeans
());
checkMemoryManagerMXBeans
(
getMemoryManagerMXBeans
());
checkMemoryManagerMXBeans
(
getMemoryManagerMXBeans
());
checkMemoryPoolMXBeans
(
getMemoryPoolMXBeans
());
checkMemoryPoolMXBeans
(
getMemoryPoolMXBeans
());
// check invalid platform MXBean
checkInvalidPlatformMXBean
();
}
}
private
static
<
T
extends
PlatformManagedObject
>
private
static
<
T
extends
PlatformManagedObject
>
void
checkPlatformMXBean
(
T
obj
,
Class
<
T
>
mxbeanInterface
,
void
checkPlatformMXBean
(
T
obj
,
Class
<
T
>
mxbeanInterface
,
String
mxbeanName
)
throws
Exception
String
mxbeanName
)
throws
Exception
{
{
int
numElements
=
(
obj
!=
null
?
1
:
0
);
// getPlatformMXBean may return null if the mxbean is not implemented
// verify local list of platform MXBeans
PlatformManagedObject
mxbean
=
getPlatformMXBean
(
mxbeanInterface
);
if
(
obj
!=
mxbean
)
{
throw
new
RuntimeException
(
"Singleton MXBean returned not matched"
);
}
int
numElements
=
obj
==
null
?
0
:
1
;
List
<?
extends
PlatformManagedObject
>
mxbeans
=
List
<?
extends
PlatformManagedObject
>
mxbeans
=
getPlatformMXBeans
(
mxbeanInterface
);
getPlatformMXBeans
(
mxbeanInterface
);
if
(
mxbeans
.
size
()
!=
numElements
)
{
if
(
mxbeans
.
size
()
!=
numElements
)
{
...
@@ -77,24 +91,46 @@ public class GetPlatformMXBeans {
...
@@ -77,24 +91,46 @@ public class GetPlatformMXBeans {
}
}
if
(
obj
!=
null
)
{
if
(
obj
!=
null
)
{
PlatformManagedObject
pmo
=
mxbeans
.
get
(
0
);
if
(
obj
!=
mxbeans
.
get
(
0
))
{
if
(
obj
!=
pmo
)
{
throw
new
RuntimeException
(
"The list returned by getPlatformMXBeans"
throw
new
RuntimeException
(
"The list returned by getPlatformMXBeans"
+
" not matched"
);
+
" not matched"
);
}
}
ObjectName
on
=
new
ObjectName
(
mxbeanName
);
ObjectName
on
=
new
ObjectName
(
mxbeanName
);
if
(!
on
.
equals
(
pmo
.
getObjectName
()))
{
if
(!
on
.
equals
(
mxbean
.
getObjectName
()))
{
throw
new
RuntimeException
(
"Unmatched ObjectName "
+
throw
new
RuntimeException
(
"Unmatched ObjectName "
+
pmo
.
getObjectName
()
+
" Expected = "
+
on
);
mxbean
.
getObjectName
()
+
" Expected = "
+
on
);
}
checkRemotePlatformMXBean
(
obj
,
platformMBeanServer
,
mxbeanInterface
,
mxbeanName
);
}
}
}
}
// verify platform MXBeans in the platform MBeanServer
// verify platform MXBeans in the platform MBeanServer
mxbeans
=
getPlatformMXBeans
(
platformMBeanServer
,
mxbeanInterface
);
private
static
<
T
extends
PlatformManagedObject
>
void
checkRemotePlatformMXBean
(
T
obj
,
MBeanServerConnection
mbs
,
Class
<
T
>
mxbeanInterface
,
String
mxbeanName
)
throws
Exception
{
PlatformManagedObject
mxbean
=
getPlatformMXBean
(
mbs
,
mxbeanInterface
);
if
((
obj
==
null
&&
mxbean
!=
null
)
||
(
obj
!=
null
&&
mxbean
==
null
))
{
throw
new
RuntimeException
(
"Singleton MXBean returned not matched"
);
}
int
numElements
=
obj
==
null
?
0
:
1
;
List
<?
extends
PlatformManagedObject
>
mxbeans
=
getPlatformMXBeans
(
mbs
,
mxbeanInterface
);
if
(
mxbeans
.
size
()
!=
numElements
)
{
if
(
mxbeans
.
size
()
!=
numElements
)
{
throw
new
RuntimeException
(
"Unmatched number of platform MXBeans "
throw
new
RuntimeException
(
"Unmatched number of platform MXBeans "
+
mxbeans
.
size
()
+
". Expected = "
+
numElements
);
+
mxbeans
.
size
()
+
". Expected = "
+
numElements
);
}
}
ObjectName
on
=
new
ObjectName
(
mxbeanName
);
if
(!
on
.
equals
(
mxbean
.
getObjectName
()))
{
throw
new
RuntimeException
(
"Unmatched ObjectName "
+
mxbean
.
getObjectName
()
+
" Expected = "
+
on
);
}
}
}
private
static
void
checkMemoryManagerMXBeans
(
List
<
MemoryManagerMXBean
>
objs
)
private
static
void
checkMemoryManagerMXBeans
(
List
<
MemoryManagerMXBean
>
objs
)
...
@@ -148,6 +184,14 @@ public class GetPlatformMXBeans {
...
@@ -148,6 +184,14 @@ public class GetPlatformMXBeans {
void
checkPlatformMXBeans
(
List
<
T
>
objs
,
Class
<
T
>
mxbeanInterface
)
void
checkPlatformMXBeans
(
List
<
T
>
objs
,
Class
<
T
>
mxbeanInterface
)
throws
Exception
throws
Exception
{
{
try
{
getPlatformMXBean
(
mxbeanInterface
);
// mxbeanInterface is not a singleton
throw
new
RuntimeException
(
mxbeanInterface
+
": not a singleton MXBean"
);
}
catch
(
IllegalArgumentException
e
)
{
// expect IAE
}
// verify local list of platform MXBeans
// verify local list of platform MXBeans
List
<?
extends
PlatformManagedObject
>
mxbeans
=
List
<?
extends
PlatformManagedObject
>
mxbeans
=
getPlatformMXBeans
(
mxbeanInterface
);
getPlatformMXBeans
(
mxbeanInterface
);
...
@@ -177,4 +221,40 @@ public class GetPlatformMXBeans {
...
@@ -177,4 +221,40 @@ public class GetPlatformMXBeans {
+
mxbeans
.
size
()
+
". Expected = "
+
objs
.
size
());
+
mxbeans
.
size
()
+
". Expected = "
+
objs
.
size
());
}
}
}
}
interface
FakeMXBean
extends
PlatformManagedObject
{};
private
static
void
checkInvalidPlatformMXBean
()
throws
IOException
{
try
{
getPlatformMXBean
(
FakeMXBean
.
class
);
// mxbeanInterface is not a singleton
throw
new
RuntimeException
(
"Expect IllegalArgumentException but not thrown"
);
}
catch
(
IllegalArgumentException
e
)
{
// expect IAE
}
try
{
getPlatformMXBeans
(
FakeMXBean
.
class
);
// mxbeanInterface is not a singleton
throw
new
RuntimeException
(
"Expect IllegalArgumentException but not thrown"
);
}
catch
(
IllegalArgumentException
e
)
{
// expect IAE
}
try
{
getPlatformMXBean
(
platformMBeanServer
,
FakeMXBean
.
class
);
// mxbeanInterface is not a singleton
throw
new
RuntimeException
(
"Expect IllegalArgumentException but not thrown"
);
}
catch
(
IllegalArgumentException
e
)
{
// expect IAE
}
try
{
getPlatformMXBeans
(
platformMBeanServer
,
FakeMXBean
.
class
);
// mxbeanInterface is not a singleton
throw
new
RuntimeException
(
"Expect IllegalArgumentException but not thrown"
);
}
catch
(
IllegalArgumentException
e
)
{
// expect IAE
}
}
}
}
test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java
0 → 100644
浏览文件 @
0e37d88a
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7024172
* @summary Test if proxy for PlatformLoggingMXBean is equivalent
* to proxy for LoggingMXBean
*
* @build LoggingMXBeanTest
* @run main LoggingMXBeanTest
*/
import
java.lang.management.*
;
import
javax.management.MBeanServer
;
import
java.util.logging.*
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
LoggingMXBeanTest
{
static
String
LOGGER_NAME_1
=
"com.sun.management.Logger"
;
static
String
LOGGER_NAME_2
=
"com.sun.management.Logger.Logger2"
;
static
String
UNKNOWN_LOGGER_NAME
=
"com.sun.management.Unknown"
;
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
MBeanServer
mbs
=
ManagementFactory
.
getPlatformMBeanServer
();
LoggingMXBean
proxy
=
ManagementFactory
.
newPlatformMXBeanProxy
(
mbs
,
LogManager
.
LOGGING_MXBEAN_NAME
,
LoggingMXBean
.
class
);
// test LoggingMXBean proxy
LoggingMXBeanTest
p
=
new
LoggingMXBeanTest
(
proxy
);
// check if the attributes implemented by PlatformLoggingMXBean
// and LoggingMXBean return the same value
PlatformLoggingMXBean
mxbean
=
ManagementFactory
.
getPlatformMXBean
(
mbs
,
PlatformLoggingMXBean
.
class
);
checkAttributes
(
proxy
,
mxbean
);
}
// same verification as in java/util/logging/LoggingMXBeanTest2
public
LoggingMXBeanTest
(
LoggingMXBean
mbean
)
throws
Exception
{
Logger
logger1
=
Logger
.
getLogger
(
LOGGER_NAME_1
);
logger1
.
setLevel
(
Level
.
FINE
);
Logger
logger2
=
Logger
.
getLogger
(
LOGGER_NAME_2
);
logger2
.
setLevel
(
null
);
/*
* Check for the existence of our new Loggers
*/
System
.
out
.
println
(
"Test Logger Name retrieval (getLoggerNames)"
);
boolean
log1
=
false
,
log2
=
false
;
List
<
String
>
loggers
=
mbean
.
getLoggerNames
();
if
(
loggers
==
null
||
loggers
.
size
()
<
2
)
{
throw
new
RuntimeException
(
"Could not Detect the presense of the new Loggers"
);
}
for
(
String
logger
:
loggers
)
{
if
(
logger
.
equals
(
LOGGER_NAME_1
))
{
log1
=
true
;
System
.
out
.
println
(
" : Found new Logger : "
+
logger
);
}
if
(
logger
.
equals
(
LOGGER_NAME_2
))
{
log2
=
true
;
System
.
out
.
println
(
" : Found new Logger : "
+
logger
);
}
}
if
(
log1
&&
log2
)
System
.
out
.
println
(
" : PASSED."
);
else
{
System
.
out
.
println
(
" : FAILED. Could not Detect the new Loggers."
);
throw
new
RuntimeException
(
"Could not Detect the presense of the new Loggers"
);
}
System
.
out
.
println
(
"Test getLoggerLevel"
);
String
l1
=
mbean
.
getLoggerLevel
(
LOGGER_NAME_1
);
System
.
out
.
println
(
" : Level for Logger "
+
LOGGER_NAME_1
+
" : "
+
l1
);
if
(!
l1
.
equals
(
Level
.
FINE
.
getName
()))
{
throw
new
RuntimeException
(
"Expected level for "
+
LOGGER_NAME_1
+
" = "
+
Level
.
FINE
.
getName
()
+
" but got "
+
l1
);
}
String
l2
=
mbean
.
getLoggerLevel
(
LOGGER_NAME_2
);
System
.
out
.
println
(
" : Level for Logger "
+
LOGGER_NAME_2
+
" : "
+
l2
);
if
(!
l2
.
equals
(
""
))
{
throw
new
RuntimeException
(
"Expected level for "
+
LOGGER_NAME_2
+
" = \"\""
+
" but got "
+
l2
);
}
String
l3
=
mbean
.
getLoggerLevel
(
UNKNOWN_LOGGER_NAME
);
System
.
out
.
println
(
" : Level for unknown logger : "
+
l3
);
if
(
l3
!=
null
)
{
throw
new
RuntimeException
(
"Expected level for "
+
UNKNOWN_LOGGER_NAME
+
" = null"
+
" but got "
+
l3
);
}
System
.
out
.
println
(
"Test setLoggerLevel"
);
mbean
.
setLoggerLevel
(
LOGGER_NAME_1
,
"INFO"
);
System
.
out
.
println
(
" : Set Level for Logger "
+
LOGGER_NAME_1
+
" to: INFO"
);
Level
l
=
logger1
.
getLevel
();
if
(
l
!=
Level
.
INFO
)
{
throw
new
RuntimeException
(
"Expected level for "
+
LOGGER_NAME_1
+
" = "
+
Level
.
INFO
+
" but got "
+
l
);
}
mbean
.
setLoggerLevel
(
LOGGER_NAME_2
,
"SEVERE"
);
System
.
out
.
println
(
" : Set Level for Logger "
+
LOGGER_NAME_2
+
" to: SERVER"
);
l
=
logger2
.
getLevel
();
if
(
l
!=
Level
.
SEVERE
)
{
throw
new
RuntimeException
(
"Expected level for "
+
LOGGER_NAME_2
+
" = "
+
Level
.
SEVERE
+
" but got "
+
l
);
}
mbean
.
setLoggerLevel
(
LOGGER_NAME_1
,
null
);
System
.
out
.
println
(
" : Set Level for Logger "
+
LOGGER_NAME_1
+
" to: null"
);
l
=
logger1
.
getLevel
();
if
(
l
!=
null
)
{
throw
new
RuntimeException
(
"Expected level for "
+
LOGGER_NAME_1
+
" = null "
+
" but got "
+
l
);
}
boolean
iaeCaught
=
false
;
System
.
out
.
println
(
" : Set Level for unknown Logger to: FINE"
);
try
{
mbean
.
setLoggerLevel
(
UNKNOWN_LOGGER_NAME
,
"FINE"
);
}
catch
(
IllegalArgumentException
e
)
{
// expected
iaeCaught
=
true
;
System
.
out
.
println
(
" : IllegalArgumentException caught as expected"
);
}
if
(!
iaeCaught
)
{
throw
new
RuntimeException
(
"Expected IllegalArgumentException for setting level for "
+
UNKNOWN_LOGGER_NAME
+
" not thrown"
);
}
iaeCaught
=
false
;
System
.
out
.
println
(
" : Set Level for Logger "
+
LOGGER_NAME_1
+
" to: DUMMY"
);
try
{
mbean
.
setLoggerLevel
(
LOGGER_NAME_1
,
"DUMMY"
);
}
catch
(
IllegalArgumentException
e
)
{
// expected
iaeCaught
=
true
;
System
.
out
.
println
(
" : IllegalArgumentException caught as expected"
);
}
if
(!
iaeCaught
)
{
throw
new
RuntimeException
(
"Expected IllegalArgumentException for invalid level."
);
}
System
.
out
.
println
(
"Test getParentLoggerName"
);
String
p1
=
mbean
.
getParentLoggerName
(
LOGGER_NAME_2
);
System
.
out
.
println
(
" : Parent Logger for "
+
LOGGER_NAME_2
+
" : "
+
p1
);
if
(!
p1
.
equals
(
LOGGER_NAME_1
))
{
throw
new
RuntimeException
(
"Expected parent for "
+
LOGGER_NAME_2
+
" = "
+
LOGGER_NAME_1
+
" but got "
+
p1
);
}
String
p2
=
mbean
.
getParentLoggerName
(
""
);
System
.
out
.
println
(
" : Parent Logger for \"\" : "
+
p2
);
if
(!
p2
.
equals
(
""
))
{
throw
new
RuntimeException
(
"Expected parent for root logger \"\" = \"\""
+
" but got "
+
p2
);
}
String
p3
=
mbean
.
getParentLoggerName
(
UNKNOWN_LOGGER_NAME
);
System
.
out
.
println
(
" : Parent Logger for unknown logger : "
+
p3
);
if
(
p3
!=
null
)
{
throw
new
RuntimeException
(
"Expected level for "
+
UNKNOWN_LOGGER_NAME
+
" = null"
+
" but got "
+
p3
);
}
}
private
static
void
checkAttributes
(
LoggingMXBean
mxbean1
,
PlatformLoggingMXBean
mxbean2
)
{
// verify logger names
List
<
String
>
loggers1
=
mxbean1
.
getLoggerNames
();
List
<
String
>
loggers2
=
mxbean2
.
getLoggerNames
();
if
(
loggers1
.
size
()
!=
loggers2
.
size
())
throw
new
RuntimeException
(
"LoggerNames: unmatched number of entries"
);
List
<
String
>
loggers3
=
new
ArrayList
<>(
loggers1
);
loggers3
.
removeAll
(
loggers2
);
if
(
loggers3
.
size
()
!=
0
)
throw
new
RuntimeException
(
"LoggerNames: unmatched loggers"
);
// verify logger's level and parent
for
(
String
logger
:
loggers1
)
{
if
(!
mxbean1
.
getLoggerLevel
(
logger
)
.
equals
(
mxbean2
.
getLoggerLevel
(
logger
)))
throw
new
RuntimeException
(
"LoggerLevel: unmatched level for "
+
logger
);
if
(!
mxbean1
.
getParentLoggerName
(
logger
)
.
equals
(
mxbean2
.
getParentLoggerName
(
logger
)))
throw
new
RuntimeException
(
"ParentLoggerName: unmatched parent logger's name for "
+
logger
);
}
}
}
test/java/
util/logging
/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java
→
test/java/
lang/management
/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java
浏览文件 @
0e37d88a
...
@@ -23,10 +23,11 @@
...
@@ -23,10 +23,11 @@
/*
/*
* @test
* @test
* @bug 6876135
* @bug 6876135
7024172
*
*
* @summary Test PlatformLoggingMXBean
* @summary Test PlatformLoggingMXBean
* This test performs similar testing as LoggingMXBeanTest.
* This test performs similar testing as
* java/util/logging/LoggingMXBeanTest.
*
*
* @build PlatformLoggingMXBeanTest
* @build PlatformLoggingMXBeanTest
* @run main PlatformLoggingMXBeanTest
* @run main PlatformLoggingMXBeanTest
...
@@ -34,6 +35,7 @@
...
@@ -34,6 +35,7 @@
import
javax.management.*
;
import
javax.management.*
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.PlatformLoggingMXBean
;
import
java.util.logging.*
;
import
java.util.logging.*
;
import
java.util.List
;
import
java.util.List
;
...
@@ -247,14 +249,8 @@ public class PlatformLoggingMXBeanTest
...
@@ -247,14 +249,8 @@ public class PlatformLoggingMXBeanTest
}
}
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
List
<
PlatformLoggingMXBean
>
result
=
PlatformLoggingMXBean
mbean
=
ManagementFactory
.
getPlatformMXBeans
(
PlatformLoggingMXBean
.
class
);
ManagementFactory
.
getPlatformMXBean
(
PlatformLoggingMXBean
.
class
);
if
(
result
.
size
()
!=
1
)
{
throw
new
RuntimeException
(
"Unexpected number of PlatformLoggingMXBean instances: "
+
result
.
size
());
}
PlatformLoggingMXBean
mbean
=
result
.
get
(
0
);
ObjectName
objname
=
mbean
.
getObjectName
();
ObjectName
objname
=
mbean
.
getObjectName
();
if
(!
objname
.
equals
(
new
ObjectName
(
LogManager
.
LOGGING_MXBEAN_NAME
)))
{
if
(!
objname
.
equals
(
new
ObjectName
(
LogManager
.
LOGGING_MXBEAN_NAME
)))
{
throw
new
RuntimeException
(
"Invalid ObjectName "
+
objname
);
throw
new
RuntimeException
(
"Invalid ObjectName "
+
objname
);
...
@@ -263,11 +259,12 @@ public class PlatformLoggingMXBeanTest
...
@@ -263,11 +259,12 @@ public class PlatformLoggingMXBeanTest
// check if the PlatformLoggingMXBean is registered in the platform MBeanServer
// check if the PlatformLoggingMXBean is registered in the platform MBeanServer
MBeanServer
platformMBS
=
ManagementFactory
.
getPlatformMBeanServer
();
MBeanServer
platformMBS
=
ManagementFactory
.
getPlatformMBeanServer
();
ObjectName
objName
=
new
ObjectName
(
LogManager
.
LOGGING_MXBEAN_NAME
);
ObjectName
objName
=
new
ObjectName
(
LogManager
.
LOGGING_MXBEAN_NAME
);
// We could call mbs.isRegistered(objName) here.
// We could call mbs.isRegistered(objName) here.
// Calling getMBeanInfo will throw exception if not found.
// Calling getMBeanInfo will throw exception if not found.
platformMBS
.
getMBeanInfo
(
objName
);
platformMBS
.
getMBeanInfo
(
objName
);
if
(!
platformMBS
.
isInstanceOf
(
objName
,
"java.
util.logging
.PlatformLoggingMXBean"
)
||
if
(!
platformMBS
.
isInstanceOf
(
objName
,
"java.
lang.management
.PlatformLoggingMXBean"
)
||
!
platformMBS
.
isInstanceOf
(
objName
,
"java.util.logging.LoggingMXBean"
))
{
!
platformMBS
.
isInstanceOf
(
objName
,
"java.util.logging.LoggingMXBean"
))
{
throw
new
RuntimeException
(
objName
+
" is of unexpected type"
);
throw
new
RuntimeException
(
objName
+
" is of unexpected type"
);
}
}
...
...
test/java/nio/channels/AsynchronousSocketChannel/Leaky.java
浏览文件 @
0e37d88a
...
@@ -28,12 +28,12 @@
...
@@ -28,12 +28,12 @@
*/
*/
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.BufferPoolMXBean
;
import
java.nio.channels.*
;
import
java.nio.channels.*
;
import
java.net.*
;
import
java.net.*
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.ThreadFactory
;
import
java.lang.management.BufferPoolMXBean
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.ManagementFactory
;
/**
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录