java - 如何从本地连接的 JNDI 查找 DomainRuntimeServiceMBean?

标签 java weblogic jndi

我广泛搜索了 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/

相关文章:

eclipse - Weblogic.xml 及其无法解析 "URL mapping class"属性

Java JNDI 查找 Microsoft Active Directory(使用 Tomcat 6),身份验证失败

java - 使用 JNDI 的 LDAP 未返回结果

java - Weblogic 部署原因 - 创建名称为 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' 的 bean 时出错

java - 无法将条目 ':app:sourceSets' 添加到缓存 taskArtifacts.bin

java - MongoDB - 如何获取查找查询的计数

java - 我的 Java 软件可以转换为 .exe 软件吗?

caching - 在服务器运行时清除 weblogic server 10.3 中的缓存

java - 了解 ejb-link 标记

java - 如何在 Eclipse 编辑器中仅显示编译错误?