如何在部署到域时以编程方式获取JBoss服务器组名称 [英] How to obtain JBoss Server Group Name programatically when deployed to a domain

查看:109
本文介绍了如何在部署到域时以编程方式获取JBoss服务器组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从部署到域的java企业应用程序中以编程方式获取jboss eap 6.x / wildfly服务器组名?

How can I obtain the jboss eap 6.x / wildfly server group name programmatically from within a java enterprise application deployed to a domain?

其他一些jboss可以通过系统属性值获取节点名称等值,但是server-group-name似乎没有以这种方式公开。

Some of the other jboss values such as node name can be obtained via system property values but server-group-name does not appear to be exposed this way.

我希望能够显示系统诊断功能中的服务器组名称(即群集名称),供技术用户验证他们正在查看正确的系统...(npe,dev,prod等)

I would like to be able to show the server group name (i.e. the cluster name) in a system diagnostics function for technical users to verify they are looking at the correct system... (npe, dev, prod etc)

推荐答案

我发现我需要使用JMX来获取此值,因为它通过MBean暴露给JVM(可通过JConsole进行验证....)

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....)

回答我自己的问题:

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);
}

如果应用程序也可能部署到独立服务器,可以查询 launchType 属性优先。有效值似乎是STANDALONE或DOMAIN。

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.

在STANDALONE模式下, serverGroup 属性不可用但是可以使用 jboss.node.name 系统属性作为替代系统标识符。

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

这篇关于如何在部署到域时以编程方式获取JBoss服务器组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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