Example usage for javax.management.remote JMXConnector getMBeanServerConnection

List of usage examples for javax.management.remote JMXConnector getMBeanServerConnection

Introduction

In this page you can find the example usage for javax.management.remote JMXConnector getMBeanServerConnection.

Prototype

public MBeanServerConnection getMBeanServerConnection() throws IOException;

Source Link

Document

Returns an MBeanServerConnection object representing a remote MBean server.

Usage

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

private void registerPulseUrlToManager(JMXConnector connection)
        throws IOException, AttributeNotFoundException, InstanceNotFoundException, MBeanException,
        ReflectionException, MalformedObjectNameException, InvalidAttributeValueException {
    if (LOGGER.infoEnabled()) {
        LOGGER.info(resourceBundle.getString("LOG_MSG_REGISTERING_APP_URL_TO_MANAGER"));
    }/*from   w w w  .  j ava  2  s.c  om*/

    // Reference to repository
    Repository repository = Repository.get();

    // Register Pulse URL if not already present in the JMX Manager
    if (connection != null) {
        MBeanServerConnection mbsc = connection.getMBeanServerConnection();

        Set<ObjectName> mbeans = mbsc.queryNames(this.MBEAN_OBJECT_NAME_MEMBER_MANAGER, null);

        for (ObjectName mbeanName : mbeans) {
            String presentUrl = (String) mbsc.getAttribute(mbeanName,
                    PulseConstants.MBEAN_MANAGER_ATTRIBUTE_PULSEURL);
            String pulseWebAppUrl = repository.getPulseWebAppUrl();
            if (pulseWebAppUrl != null && (presentUrl == null || !pulseWebAppUrl.equals(presentUrl))) {
                if (LOGGER.fineEnabled()) {
                    LOGGER.fine(resourceBundle.getString("LOG_MSG_SETTING_APP_URL_TO_MANAGER"));
                }
                Attribute pulseUrlAttr = new Attribute(PulseConstants.MBEAN_MANAGER_ATTRIBUTE_PULSEURL,
                        pulseWebAppUrl);
                mbsc.setAttribute(mbeanName, pulseUrlAttr);
            } else {
                if (LOGGER.fineEnabled()) {
                    LOGGER.fine(resourceBundle.getString("LOG_MSG_APP_URL_ALREADY_PRESENT_IN_MANAGER"));
                }
            }
        }
    }
}