Example usage for org.springframework.jmx JmxException JmxException

List of usage examples for org.springframework.jmx JmxException JmxException

Introduction

In this page you can find the example usage for org.springframework.jmx JmxException JmxException.

Prototype

public JmxException(String msg) 

Source Link

Document

Constructor for JmxException.

Usage

From source file:org.apache.uima.examples.as.GetMetaRequest.java

/**
 * Creates a connection to an MBean Server identified by
 * <code>remoteJMXServerHostName and remoteJMXServerPort</code>
 * //from  w ww.  ja  v  a  2 s  . c  om
 * @param remoteJMXServerHostName
 *          - MBeanServer host name
 * @param remoteJMXServerPort
 *          - MBeanServer port
 * @return - none
 * 
 * @throws Exception
 */
private static void initialize(String jmxDomain, String remoteJMXServerHostname, String remoteJMXServerPort)
        throws Exception {
    // Construct connect string to the JMX MBeanServer
    String remoteJmxUrl = "service:jmx:rmi:///jndi/rmi://" + remoteJMXServerHostname + ":" + remoteJMXServerPort
            + "/jmxrmi";

    try {
        JMXServiceURL url = new JMXServiceURL(remoteJmxUrl);
        jmxc = JMXConnectorFactory.connect(url, null);
        brokerMBeanServer = jmxc.getMBeanServerConnection();
        // Its possible that the above code succeeds even though the broker runs
        // with no JMX Connector. At least on windows the above does not throw an
        // exception as expected. It appears that the broker registers self JVMs MBeanServer
        // but it does *not* register any Connections, nor Queues. The code below 
        // checks if the MBean server we are connected to has any QueueMBeans registered.
        // A broker with jmx connector should have queue mbeans registered and thus
        //  the code below should always succeed. Conversely, a broker with no jmx connector
        // reports no queue mbeans.

        //  Query broker MBeanServer for QueueMBeans
        Set queueSet = brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Queue"),
                (QueryExp) null);
        if (queueSet.isEmpty()) { //  No QueueMBeans, meaning no JMX support
            throw new JmxException("ActiveMQ Broker Not Configured With JMX Support");
        }
    } catch (Exception e) {
        return;
    }
    // Query JMX Server for Broker MBean. We need the broker's name from an MBean to construct
    // queue query string.

    for (Object nameObject : brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Broker"),
            (QueryExp) null)) {
        ObjectName brokerObjectName = (ObjectName) nameObject;
        if (brokerObjectName.getCanonicalName().endsWith("Type=Broker")) {
            // Extract just the name from the canonical name
            brokerName = brokerObjectName.getCanonicalName().substring(0,
                    brokerObjectName.getCanonicalName().indexOf(","));
            initialized = true;
            break; // got the broker name
        }
    }
}