Example usage for javax.management MBeanServerConnection setAttribute

List of usage examples for javax.management MBeanServerConnection setAttribute

Introduction

In this page you can find the example usage for javax.management MBeanServerConnection setAttribute.

Prototype

public void setAttribute(ObjectName name, Attribute attribute)
        throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException, IOException;

Source Link

Document

Sets the value of a specific attribute of a named MBean.

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 ww.j a  v a2  s  .co  m

    // 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"));
                }
            }
        }
    }
}