`
hanhan8020
  • 浏览: 45645 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Accessing WebLogic Server MBeans with JMX (四)

阅读更多

Make Local Connections to the Runtime MBean Server

....

private String getDomainName() {
        InitialContext ctx = null;
        String domainName = "DomainName";
        try {
            ObjectName service = new ObjectName(
            "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
            ctx = new InitialContext();

            MBeanServer server = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");

            ObjectName drt = (ObjectName) server.getAttribute(service, "DomainConfiguration");
            domainName = (String) server.getAttribute(drt, "Name");

            log.info("PfConfiguration Override Domain Name: " + domainName);
        } catch (Exception e) {
            log.error("Error fetching Weblogic Server Info", e);
        } finally {
            if (ctx != null) {
                try {
                    ctx.close();
                } catch (NamingException e) {
                    log.error("Error closing InitialContext :"+e.toString(), e);
                }
            }

        }
        return System.getProperty("pfPortalEnv")+"."+domainName;
    }

    private String getDomainNodeName() {
        InitialContext ctx = null;
        String domainName = "DomainName";
        String nodeName = "DomainNode";
        try {
            ObjectName service = new ObjectName(
            "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
            ctx = new InitialContext();

            MBeanServer server = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");

            ObjectName rt = (ObjectName) server.getAttribute(service, "ServerRuntime");
            nodeName = (String) server.getAttribute(rt, "Name");

            ObjectName drt = (ObjectName) server.getAttribute(service, "DomainConfiguration");
            domainName = (String) server.getAttribute(drt, "Name");

            log.info("PfConfiguration Override Domain Node Name: " + domainName + "." + nodeName);
        } catch (Exception e) {
            log.error("Error fetching Weblogic Server Info", e);
        } finally {
            if (ctx != null) {
                try {
                    ctx.close();
                } catch (NamingException e) {
                    log.error("Error closing InitialContext :"+e.toString(), e);
                }
            }

        }
        return System.getProperty("pfPortalEnv")+"."+domainName+"."+nodeName;
    }

   
     public String getNodeName() {
        InitialContext ctx = null;
        String nodeName = "DomainNode";
        try {
          ObjectName service = new ObjectName(
          "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
          ctx = new InitialContext();

          MBeanServer server = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");

          ObjectName rt = (ObjectName) server.getAttribute(service, "ServerRuntime");
          nodeName = (String) server.getAttribute(rt, "Name");
        } catch (Exception e) {
          log.error("Error fetching Weblogic Server Info", e);
        } finally {
          if (ctx != null) {
            try {
              ctx.close();
            } catch (NamingException e) {
              log.error("Error closing InitialContext :"+e.toString(), e);
            }
          }

        }
        return nodeName;
  }

...........

..........

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics