Kevin Zheng (KevinZheng_GCS)
Director, Software Solutions Engineering
Pegasystems Inc.
KevinZheng_GCS Member since 2009 9 posts
Posted: August 10, 2016
Last activity: April 6, 2017
Posted: 10 Aug 2016 11:27 EDT
Last activity: 6 Apr 2017 5:58 EDT

JMX MBean Sample Code for Pega MBeans

As I have seen a lot of questions regarding JMX API in pega, I have put together an example here - the code is generic except the serviceUrl, which is app server dependent (my example here is for jboss eap 6.x) - you can create a simple java step and run it - feel free to provide your feedback so that all the community users can benefit.

        String host = "host";  
        int port = 9999;  // management-native port  
        String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;  
        System.out.println("\n\n\t****  urlString: "+urlString);;  
        javax.management.remote.JMXServiceURL serviceURL = new javax.management.remote.JMXServiceURL(urlString);  
        java.util.Map map = new java.util.HashMap();  
        String[] credentials = new String[] { "user", "password" };  
        map.put("jmx.remote.credentials", credentials);  
        javax.management.remote.JMXConnector jmxConnector = javax.management.remote.JMXConnectorFactory.connect(serviceURL, map);  
        javax.management.MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();  
    // Quick way to execute getNodes mBean      
    ObjectName oname = new ObjectName("com.pega.pegarules.management.internal.ListenerManagement");    
      String result = (String) connection.invoke(oname, "getNodes", new Object[0], new String[0]);      
    // result is XML. Parse it yourself  
        // Longer exercise to walk through all domains, all names, and operations within  
        int count = connection.getMBeanCount();  
        System.out.println("Total MBean count:" + count);  
        // Get domain list  
        String[] domains = connection.getDomains();  
        for (String domain: domains)  
          System.out.println("Domain: " + domain);  
        // Get list of object names  
        Set<javax.management.ObjectName> names = connection.queryNames(null,null);  
        for (javax.management.ObjectName name:names)  
          if (name.getDomain().contains("com.pega"))  
             System.out.println("ObjectName: " + name);  
            javax.management.MBeanInfo info = connection.getMBeanInfo(name);  
            for (javax.management.MBeanOperationInfo operation : info.getOperations()) {  
                 System.out.println("operations: "+operation.getName());  
                 // invoking an operation for NodeManagement mBean  
                 if (operation.getName().equals("getNodes"))  
                     System.out.println("invoking: " + name + "operation: " + operation.getName());  
                     System.out.println(connection.invoke(name, operation.getName(),new Object[0],new String[0]));  
    } catch (Exception e)  
        System.out.println("Caught exception: " + e);  

***Updated by moderator: Lochan to add Categories***

Data Integration
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Discussion, please write a new Discussion.