Index Changes
This is version 11. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]
ESB Console Home

How do I figure out all the details about a Target Runtime Environment

For the Trouble-Shooter/Analyst

The JmxExplorer.jar(info) is very useful in figuring out a target environment and can be used to diagnose problems at customer environments.

Run the jar file in an environment and retrieve All MBean information in an output file that is generated when the code is exercised.

Just place the jar file in a convenient place on the file system and run:

java -cp .;JmxExplorer.jar org.glassfish.openesb.management.test.Main

You will be prompted to enter host, port, userName, password and name of output file. Once you provide the values, it generates the output.

If you use the JRMP port (default 8686) you would not need any other jar file other than the provided JmxExplorer.jar.

If you want to look at the source code, it is checked into the esb-console project at: https://esb-console.dev.java.net/source/browse/esb-console/trunk/JmxExplorer/

There's more you can do if you are a Developer

In-fact if you are a developer and have a penchant for doing more, the JmxExplorer.jar(info) file can be included as a class-library in your programs and can be used to retrieve interesting information about any runtime environmant.

Some operations of interest in the org.glassfish.openesb.management.Explorer class include:

// Retrieves all Object names of MBeans deployed on the target environment
public static final List<ObjectName> findAll(MBeanServerConnection connection);

// Get MBeanInfo of each ObjectName
public static final MBeanInfo getMBeanInfo(MBeanServerConnection connection, ObjectName anObjectName);

// Given a search criteria, search for all MBeans that match it.
// The match can be based on Class Name, Package Name, Attribute Names, Operation Names, Domain Names, etc.
public static final List<ObjectName> findMatchingMBeans(MBeanServerConnection connection, List<ObjectName> objectNames, Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap);

For example, the following code-fragment searches the target environment for all MBeans that are:

  1. Implemented by classes that have either "com.stc" or "org.glassfish.openesb" in their package name, or,
  2. Implemented by classes that have "ServerProxyMBean" in their names, or,
  3. Have attributes named either "restartRequired" or "threadPoolSize", or,
  4. Have operations named "getProxyOperation", or,
  5. Are registered with a domain name of either "com.sun.jbi" or "amx" or "org.glassfish"
                Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap = new HashMap<SearchCriteriaKey, String /*Semi-colon separated values*/>();

                criteriaMap.put(SearchCriteriaKey.PACKAGE_NAME, "com.stc; org.glassfish.openesb");
                criteriaMap.put(SearchCriteriaKey.CLASS_NAME, "ServerProxyMBean");
                criteriaMap.put(SearchCriteriaKey.ATTRIBUTE_NAME, "restartRequired; threadPoolSize");
                criteriaMap.put(SearchCriteriaKey.OPERATION_NAME, "getProxyOperation");
                criteriaMap.put(SearchCriteriaKey.DOMAIN_NAME, "com.sun.jbi; amx; org.glassfish");

                List<ObjectName> objectNameList = Explorer.findMatchingMBeans(connection, allObjectNamesList, criteriaMap);
                if(objectNameList != null) {
                    for(ObjectName objectName : objectNameList) {
                        System.out.println(objectName.getCanonicalName());
                        MBeanInfo info = Explorer.getMBeanInfo(connection, objectName);
                        System.out.println(Explorer.dump(info));
                    }
                }

The following is a typical code sample of exercising the library:

package org.glassfish.openesb.management.test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.glassfish.openesb.management.CapsJmxObjectNames;
import org.glassfish.openesb.management.Explorer;
import org.glassfish.openesb.management.Utilities;
import org.glassfish.openesb.management.client.ConnectionFactory;

/**
 * Code sample to:
 *    1. List all MBeans and their information in a target environment
 *    2. For all the MBeans in the target system, find and display all information about  
 *       MBeans whose class implementations have "com.stc" as part of their package name
 * 
 * @author graj
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        String hostName = Utilities.getUserInput("Enter Instance host name <localhost> :", "localhost");
        String portString = Utilities.getUserInput("Enter Instance administration port <8686> :", "8686");
        String userName = Utilities.getUserInput("Enter user name :", null);
        String password = Utilities.getUserInput("Enter user password  :", null);
        int port = new Integer(portString);
        String outputFileName = Utilities.getUserInput("Enter output file name <output.txt>  :", "output.txt");

        File outputFile = null;
        outputFile = new File(outputFileName);
        try {
            outputFile.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        MBeanServerConnection connection = null;
        ObjectName anObjectName = null;
        List<ObjectName> objectNameList = new ArrayList<ObjectName>();
        boolean result = false;
        MBeanInfo info = null;

        connection = ConnectionFactory.getInstance(hostName, port, userName, password);
        if (connection != null) {
            System.out.println("Connection Successful.");
            try {
                anObjectName = CapsJmxObjectNames.getServerProxyMBeanObjectName();
                result = connection.isRegistered(anObjectName);
                if (result == true) {
                    System.out.println(CapsJmxObjectNames.SERVER_PROXY_MBEAN_NAME + " is registered.");
                } else {
                    System.out.println(CapsJmxObjectNames.SERVER_PROXY_MBEAN_NAME + " is NOT registered.");
                }
                objectNameList = Explorer.findAll(connection);
                if (objectNameList != null) {
                    String contents = "";
                    for (ObjectName objectName : objectNameList) {
                        info = Explorer.getMBeanInfo(connection, objectName);
                        contents += Explorer.dump(connection, objectName, info);
                    }

                    Utilities.setContents(outputFile, contents);
                }
                System.out.println("***************************************************");
                Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap = new HashMap<SearchCriteriaKey, String /*Semi-colon separated values*/>();
                criteriaMap.put(SearchCriteriaKey.PACKAGE_NAME, "com.stc");
                objectNameList = Explorer.findMatchingMBeans(connection, objectNameList, criteriaMap);
                if(objectNameList != null) {
                    for(ObjectName objectName : objectNameList) {
                        System.out.println(objectName.getCanonicalName());
                        info = Explorer.getMBeanInfo(connection, objectName);
                        System.out.println(Explorer.dump(connection, objectName, info));
                    }
                }
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedObjectNameException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Connection Failed.");
        }
    }
}


Back to How-Tos


Number of visits: 45

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 14-Apr-10 21:38 PM, -0700 by Gopalan Suresh Raj