Module java.management
Package javax.management

Class JMX

java.lang.Object
javax.management.JMX

public class JMX extends Object
JMX API中的静态方法。此类没有实例。
自:
1.6
  • Field Details

  • Method Details

    • newMBeanProxy

      public static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)

      在本地或远程MBean服务器中为标准MBean创建代理。

      如果您有一个包含MBean的MBean服务器mbs,该MBean具有ObjectName name,并且如果MBean的管理接口由Java接口MyMBean描述,则可以像这样为MBean构建代理:

       MyMBean proxy = JMX.newMBeanProxy(mbs, name, MyMBean.class);
       

      例如,假设MyMBean如下所示:

       public interface MyMBean {
           public String getSomeAttribute();
           public void setSomeAttribute(String value);
           public void someOperation(String param1, int param2);
       }
       

      然后您可以执行:

      • proxy.getSomeAttribute()将导致调用mbs.getAttribute(name, "SomeAttribute")
      • proxy.setSomeAttribute("whatever")将导致调用mbs.setAttribute(name, new Attribute("SomeAttribute", "whatever"))
      • proxy.someOperation("param1", 2)将被转换为调用mbs.invoke(name, "someOperation", <etc>)

      此方法返回的对象是一个Proxy,其InvocationHandler是一个MBeanServerInvocationHandler

      此方法等效于newMBeanProxy(connection, objectName, interfaceClass, false)

      类型参数:
      T - 允许编译器知道如果interfaceClass参数是MyMBean.class,则返回类型是MyMBean
      参数:
      connection - 要转发到的MBean服务器。
      objectName - connection中的MBean的名称。
      interfaceClass - MBean导出的管理接口,返回的代理也将实现该接口。
      返回:
      新代理实例。
      抛出:
      IllegalArgumentException - 如果interfaceClass不是符合MBean接口
    • newMBeanProxy

      public static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass, boolean notificationEmitter)

      在本地或远程MBean服务器中为标准MBean创建代理,该代理还可以支持NotificationEmitter的方法。

      此方法的行为与newMBeanProxy(MBeanServerConnection, ObjectName, Class)相同,但如果notificationEmittertrue,则假定MBean是NotificationBroadcasterNotificationEmitter,返回的代理将实现NotificationEmitter以及interfaceClass。在代理上调用NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)将导致调用MBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object),其他方法也类似适用于NotificationBroadcasterNotificationEmitter

      类型参数:
      T - 允许编译器知道如果interfaceClass参数是MyMBean.class,则返回类型是MyMBean
      参数:
      connection - 要转发到的MBean服务器。
      objectName - connection中的MBean的名称。
      interfaceClass - MBean导出的管理接口,返回的代理也将实现该接口。
      notificationEmitter - 通过connection转发其方法使返回的代理实现NotificationEmitter
      返回:
      新代理实例。
      抛出:
      IllegalArgumentException - 如果interfaceClass不是符合MBean接口
    • newMXBeanProxy

      public static <T> T newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)
      创建本地或远程MBean服务器中MXBean的代理。

      如果您有一个包含具有ObjectName name的MXBean的MBean服务器mbs,并且如果MXBean的管理接口由Java接口MyMXBean描述,则可以像这样构造MXBean的代理:

       MyMXBean proxy = JMX.newMXBeanProxy(mbs, name, MyMXBean.class);
       

      例如,假设MyMXBean如下所示:

       public interface MyMXBean {
           public String getSimpleAttribute();
           public void setSimpleAttribute(String value);
           public MemoryUsage getMappedAttribute();
           public void setMappedAttribute(MemoryUsage memoryUsage);
           public MemoryUsage someOperation(String param1, MemoryUsage param2);
       }
       

      那么:

      • proxy.getSimpleAttribute()将导致调用mbs.getAttribute(name, "SimpleAttribute")

      • proxy.setSimpleAttribute("whatever")将导致调用mbs.setAttribute(name, new Attribute("SimpleAttribute", "whatever"))

        因为String是一个简单类型,在MXBean的上下文中不会改变。MXBean代理的行为与标准MBean代理相同(请参阅newMBeanProxy)对于属性SimpleAttribute

      • proxy.getMappedAttribute()将导致调用mbs.getAttribute("MappedAttribute")。MXBean映射规则意味着属性MappedAttribute的实际类型将是CompositeData,这是mbs.getAttribute调用将返回的内容。然后代理将使用MXBean映射规则将CompositeData转换回预期类型MemoryUsage

      • 类似地,proxy.setMappedAttribute(memoryUsage)将在调用mbs.setAttribute之前将MemoryUsage参数转换为CompositeData

      • proxy.someOperation("whatever", memoryUsage)将把MemoryUsage参数转换为CompositeData并调用mbs.invoke。由mbs.invoke返回的值也将是CompositeData,代理将使用MXBean映射规则将其转换为预期类型MemoryUsage

      此方法返回的对象是一个Proxy,其InvocationHandler是一个MBeanServerInvocationHandler

      此方法等效于newMXBeanProxy(connection, objectName, interfaceClass, false)

      类型参数:
      T - 允许编译器知道如果interfaceClass参数是MyMXBean.class,则返回类型是MyMXBean
      参数:
      connection - 要转发到的MBean服务器。
      objectName - 要转发到的connection中的MBean的名称。
      interfaceClass - 将由返回的代理实现的MXBean接口。
      返回:
      新代理实例。
      抛出:
      IllegalArgumentException - 如果interfaceClass不是符合MXBean接口
    • newMXBeanProxy

      public static <T> T newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass, boolean notificationEmitter)

      为本地或远程MBean服务器中的MXBean创建代理,该代理还可以支持NotificationEmitter的方法。

      此方法的行为与newMXBeanProxy(MBeanServerConnection, ObjectName, Class)相同,但是如果notificationEmittertrue,则假定MXBean是NotificationBroadcasterNotificationEmitter,返回的代理将实现NotificationEmitter以及interfaceClass。在代理上调用NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)将导致调用MBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object),其他方法也类似。

      类型参数:
      T - 允许编译器知道如果interfaceClass参数是MyMXBean.class,则返回类型是MyMXBean
      参数:
      connection - 要转发到的MBean服务器。
      objectName - 要转发到的connection中的MBean的名称。
      interfaceClass - 将由返回的代理实现的MXBean接口。
      notificationEmitter - 使返回的代理通过connection转发其方法来实现NotificationEmitter
      返回:
      新代理实例。
      抛出:
      IllegalArgumentException - 如果interfaceClass不是符合MXBean接口
    • isMXBeanInterface

      public static boolean isMXBeanInterface(Class<?> interfaceClass)

      测试接口是否为MXBean接口。如果接口是公共的,并且带有@MXBean@MXBean(true)注解,或者如果它没有@MXBean注解并且其名称以"MXBean"结尾,则接口是MXBean接口。

      参数:
      interfaceClass - 候选接口。
      返回:
      如果interfaceClass符合MXBean接口,则返回true。
      抛出:
      NullPointerException - 如果interfaceClass为null。