我广泛搜索了 Weblogic 文档:
Oracle 站点上的所有文档以及我迄今为止找到的所有示例仅显示如何通过远程连接或本地 MBeanServer
实例获取对此 MBean 的引用。
提到本地连接的一点是模糊且不完整的:
Absolute JNDI name of the MBean server. The JNDI name must start with
/jndi/
and be followed by one of the JNDI names described in Table 4-1.
表 4-1 显示:
MBean Server JNDI Name
Domain Runtime MBean Server weblogic.management.mbeanservers.domainruntime
这不起作用,我尝试转储 JNDI 树,但在其中找不到任何相关内容。
我在 AdminServer
上,所以这不是问题。
我能找到的有效说明是获取对 MBServer
实例的引用,但这不是我需要的;示例:(MBeanServer) ctx.lookup("java:comp/env/jmx/domainRuntime");
但这对我没有任何好处,它是 MBeanServer
的一个实例,我不想挖掘 ObjectName
内容的所有间接内容。
我需要引用的是DomainRuntimeServiceMBean接口(interface):
我需要的是能够获取 DomainRuntimeServiceMBean
的实例 - JavaDoc
最佳答案
简短回答
类型安全接口(interface)均已弃用,您必须手动执行查找/树遍历。
As of 9.0, the MBeanHome interface and all type-safe interfaces for WebLogic Server MBeans are deprecated. Instead, JMX applications that interact with WebLogic Server MBeans should use standard JMX design patterns in which clients use the javax.management.MBeanServerConnection interface to discover MBeans, attributes, and attribute types at runtime.
长答案
private InitialContext ctx;
private MBeanServer domain;
private ObjectName domainObjectName;
在构造函数中:
ctx = new InitialContext();
this.domain = (MBeanServer) ctx.lookup("java:comp/env/jmx/domainRuntime");
this.domainObjectName = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
在你的方法中:
final ObjectName dr = (ObjectName) this.domain.getAttribute(domainObjectName, "DomainRuntime");
final ObjectName dm = (ObjectName) this.domain.getAttribute(dr, "DeploymentManager");
final ObjectName[] adrs = (ObjectName[]) this.domain.getAttribute(dm, "AppDeploymentRuntimes");
for (final ObjectName on : adrs)
{
if (this.domain.getAttribute(on, "ApplicationName").equals(appName))
{
this.domain.invoke(on, "stop", null, null);
break;
}
}
当然,现在我必须编写自己的类型安全的便利类来包装所有这些冗长的废话!
关于java - 如何从本地连接的 JNDI 查找 DomainRuntimeServiceMBean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761738/