如何获取平台MBeanServer的JMXConnectorServer? [英] How to get the JMXConnectorServer of the platform MBeanServer?

查看:498
本文介绍了如何获取平台MBeanServer的JMXConnectorServer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java程序提供服务,可以通过调用JMX MBean上的方法通过RMI调用。服务正在运行没有问题,但我面临的问题是如何关闭服务,而不会中断一个潜在的新的并发请求的服务。



一个解决方案问题是等待所有JMX连接被关闭,然后(当没有更多的后台活动时)关闭进程。 JMXConnectorServer 有一个方法 getConnectionIds() ,但我已经陷入了以下问题: / p>

如何获取平台MBean服务器的JMXConnectorServer实例,即 ManagementFactory.getPlatformMBeanServer()返回的服务器

解决方案

AFAIK,不可能获得 JMXConnectorServer getPlatformMBeanServer()自动创建,但您可以使平台MBean服务器使用您自己创建的连接器服务器实例。



执行此操作时,重要的是 com.sun.management.jmxremote * 系统属性未设置,以便平台MBean服务器不会自动设置连接器服务器。



示例:如果使用系统属性配置JMX远程访问

  -Dcom.sun.management.jmxremote.port = 1919 
-Dcom.sun.management.jmxremote.authenticate = false
-Dcom.sun .management.jmxremote.ssl = false

删除这些系统属性并以编程方式配置您自己的连接器服务器以下代码:

  int jmxPort = 1919; 
LocateRegistry.createRegistry(jmxPort);

MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
//或:MBeanServer beanServer = MBeanServerFactory.createMBeanServer(); //不注册默认平台MBeans

JMXServiceURL jmxUrl
= new JMXServiceURL(service:jmx:rmi:/// jndi / rmi:// localhost:+ jmxPort + / jmxrmi);
JMXConnectorServer connectorServer
= JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl,null,beanServer);

connectorServer.start();

来自Oracle的技术说明包含当您要使用身份验证和SSL时手动连接器服务器设置的另一个示例。


I have a Java program providing services which can be invoked by calling methods on an JMX MBean via RMI. The service is running without problems, but I am facing the question of how to shut down the service without interrupting a potential new concurrent request to the service.

One solution for this problem would be to wait for all JMX connections to be closed and only then (and when there is no more background activity) to shut down the process. JMXConnectorServer has a method getConnectionIds() that I could use for that, but I already got stuck with the following question:

How do I get the JMXConnectorServer instance of the platform MBean server, i.e. the server returned by ManagementFactory.getPlatformMBeanServer()?

解决方案

AFAIK, it is not possible to get the JMXConnectorServer which is automatically created by getPlatformMBeanServer(), but you can make the platform MBean server use a connector server instance that you created yourself.

When you do this, it is important that the com.sun.management.jmxremote* system properties are unset, so that the platform MBean server does not automatically set up a connector server.

Example: If you configured the JMX remote access with the system properties

-Dcom.sun.management.jmxremote.port=1919
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

remove these system properties and configure your own connector server programmatically with the following code:

int jmxPort = 1919;
LocateRegistry.createRegistry(jmxPort);

MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
// or: MBeanServer beanServer = MBeanServerFactory.createMBeanServer(); // doesn't register the default platform MBeans

JMXServiceURL jmxUrl 
    = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi");
JMXConnectorServer connectorServer
    = JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, beanServer);

connectorServer.start();

This tech note from Oracle contains another example for a manual connector server setup when you want to use authentication and SSL.

这篇关于如何获取平台MBeanServer的JMXConnectorServer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆