【问题标题】:How do I lookup DomainRuntimeServiceMBean from JNDI from a Local Connection?如何从本地连接的 JNDI 中查找 DomainRuntimeServiceMBean?
【发布时间】:2014-02-13 17:48:57
【问题描述】:

我已经广泛搜索了 Weblogic 文档:

Oracle 站点上的所有文档以及我目前找到的所有示例都只显示了如何通过远程连接或本地 MBeanServer 的实例获取对此 MBean 的引用。

提到本地连接的那一点是模糊和不完整的:

MBean 服务器的绝对 JNDI 名称。 JNDI 名称必须以 /jndi/ 后跟表中描述的 JNDI 名称之一 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 接口:

我需要的是能够获得DomainRuntimeServiceMBean - JavaDoc 的实例

【问题讨论】:

    标签: java weblogic jndi


    【解决方案1】:

    简答

    类型安全接口都已弃用,您必须手动进行查找/树遍历。

    从 9.0 开始,MBeanHome 接口和所有类型安全的接口用于 不推荐使用 WebLogic Server MBean。相反,JMX 应用程序 与 WebLogic Server MBean 交互应使用标准 JMX 设计 客户使用的模式 用于发现 MBean 的 javax.management.MBeanServerConnection 接口, 属性,以及运行时的属性类型。

    长答案

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

    当然,现在我必须编写我自己的类型安全的便利类来包装所有这些冗长的废话!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      相关资源
      最近更新 更多