Access Mbeans on weblogic

jmxmbeansweblogic

From the documentation of oracle :

Domain Runtime MBean Server : This MBean server also acts as a single
point of access for MBeans that reside on Managed Servers.

what i want to do is to use this fact to access all my custom mBeans scattered in several managed servers.
for example assume that i have two nodes server-1 server-2 .
how can i access all of the custom mBeans on both server-1 server-2 by connecting to the administrator node ?

i dont want to remotly access each node to return the result i want a single entry point
i managed to get the names of the servers and the states and other information by doing this

    JMXConnector connector;
            ObjectName service;
            MBeanServerConnection connection;
            String protocol = "t3"; 
        Integer portInteger = Integer.valueOf(<admin server port>);

      int port = portInteger.intValue();
      String jndiroot = "/jndi/";
      String mserver = "weblogic.management.mbeanservers.runtime"; 

      JMXServiceURL serviceURL = new JMXServiceURL(protocol, "<serverName>", port,
      jndiroot + mserver);  

      Hashtable h = new Hashtable();
      h.put(Context.SECURITY_PRINCIPAL, "weblogic");
      h.put(Context.SECURITY_CREDENTIALS, "weblogicpass");
      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
         "weblogic.management.remote");
      h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
      connector = JMXConnectorFactory.connect(serviceURL, h);
      connection = connector.getMBeanServerConnection();  service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
      ObjectName[] ons = (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
       int length = (int) ons.length;

      for (int i = 0; i < length; i++) {
         String name = (String) connection.getAttribute(ons[i],
            "Name");
         String state = (String) connection.getAttribute(ons[i],
            "State");
          String internalPort = (String) connection.getAttribute(ons[i],"ListenPort");
         System.out.println("Server name: " + name + ".   Server state: "
            + state);

but i need to access the custom Mbeans created on each server and not only the information

Best Answer

maybe my question wasnt clear but i found an answer and i will share it here now : Question summary : i need to access custom mBeans exists in a managed server by connecting to the administration server from a client application.

Answer : to do that you need to deploy your application to the administrator server (i tried remote but it didn't work )

you need to connect to the DomainRuntimeServiceMBean because it provide a common access point for navigating to all runtime and configuration MBeans in the domain .

when searching for the Object name add Location=

here is the code:

    Hashtable props = new Hashtable();
          props.put(Context.INITIAL_CONTEXT_FACTORY,
                    "weblogic.jndi.WLInitialContextFactory");

          props.put(Context.SECURITY_PRINCIPAL,   "<userName>");
          props.put(Context.SECURITY_CREDENTIALS, "<password>");
          Context ctx = new InitialContext(props);
  MBeanServer    server = (MBeanServer)ctx.lookup("java:comp/env/jmx/domainRuntime");


         ObjectName on =new ObjectName("com.<companyName>:Name=<Name>,Type=<Type>,Location=<managed_server_name>");
         boolean boolresult=(Boolean)server.invoke(on, "<method_Name>",
         new Object[]{"<ARG1>","<ARG2>","<ARG3>"}
         ,new String[]{"java.lang.String","java.lang.String","java.lang.String"}); 
         out.print(boolresult);
Related Topic