Example usage for org.springframework.jmx.support JmxUtils locateMBeanServer

List of usage examples for org.springframework.jmx.support JmxUtils locateMBeanServer

Introduction

In this page you can find the example usage for org.springframework.jmx.support JmxUtils locateMBeanServer.

Prototype

public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException 

Source Link

Document

Attempt to find a locally running MBeanServer .

Usage

From source file:org.springframework.jmx.access.ConnectorDelegate.java

/**
 * Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}:
 * to the specified JMX service, or to a local MBeanServer if no service URL specified.
 * @param serviceUrl the JMX service URL to connect to (may be {@code null})
 * @param environment the JMX environment for the connector (may be {@code null})
 * @param agentId the local JMX MBeanServer's agent id (may be {@code null})
 *///from   w w  w  . j a v a2 s  . c  o  m
public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map<String, ?> environment,
        @Nullable String agentId) throws MBeanServerNotFoundException {

    if (serviceUrl != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]");
        }
        try {
            this.connector = JMXConnectorFactory.connect(serviceUrl, environment);
            return this.connector.getMBeanServerConnection();
        } catch (IOException ex) {
            throw new MBeanServerNotFoundException(
                    "Could not connect to remote MBeanServer [" + serviceUrl + "]", ex);
        }
    } else {
        logger.debug("Attempting to locate local MBeanServer");
        return JmxUtils.locateMBeanServer(agentId);
    }
}

From source file:org.springframework.jmx.support.MBeanServerFactoryBean.java

/**
 * Attempt to locate an existing {@code MBeanServer}.
 * Called if {@code locateExistingServerIfPossible} is set to {@code true}.
 * <p>The default implementation attempts to find an {@code MBeanServer} using
 * a standard lookup. Subclasses may override to add additional location logic.
 * @param agentId the agent identifier of the MBeanServer to retrieve.
 * If this parameter is {@code null}, all registered MBeanServers are
 * considered./*from  w w w .  j  a v a2s  .  c o  m*/
 * @return the {@code MBeanServer} if found
 * @throws org.springframework.jmx.MBeanServerNotFoundException
 * if no {@code MBeanServer} could be found
 * @see #setLocateExistingServerIfPossible
 * @see JmxUtils#locateMBeanServer(String)
 * @see javax.management.MBeanServerFactory#findMBeanServer(String)
 */
protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException {
    return JmxUtils.locateMBeanServer(agentId);
}