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

...........

..........

你可能感兴趣的:(weblogic)