Discussion
Pegasystems Inc.
US
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.
try
{
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]));
}
}
}
}
jmxConnector.close();
} catch (Exception e)
{
System.out.println("Caught exception: " + e);
}
***Updated by moderator: Lochan to add Categories***