How to obtain JBoss Server Group Name programatically when deployed to a domain

瘦欲@ 提交于 2019-12-04 21:51:42

One other (and maybe better) way to do it is to use the management API https://docs.jboss.org/author/display/WFLY8/Management+API+reference .

I've discovered that I need to use JMX to obtain this value as its exposed via an MBean to the JVM (verifyable via JConsole....)

So answering my own question:

try {
    ObjectName serverMBean = new ObjectName("jboss.as:management-root=server");
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    String serverGroupName = (String) ManagementFactory.getPlatformMBeanServer().getAttribute(serverMBean, "serverGroup");
    logger.info("JBoss server group name is" + serverGroupName);
} catch (Exception e) {
    logger.error("Unable to identify JBoss server-group-name", e);
}

If the application might also be deployed to a standalone server one could query the launchType attribute first. Valid values appear to be STANDALONE or DOMAIN.

In STANDALONE mode the serverGroup attribute is not available however one could use the jboss.node.name system property as an alternative system identifier.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!