Java MBean registerMBean(MBeanServer server, String agentName, Map attrs, Object mbeanObject)

Here you can find the source of registerMBean(MBeanServer server, String agentName, Map attrs, Object mbeanObject)

Description

register M Bean

License

Open Source License

Parameter

Parameter Description
server a parameter
agentName a parameter
mbeanType a parameter
mbeanName a parameter
mbeanObject a parameter

Exception

Parameter Description
JMException an exception

Return

The ObjectName of the MBean if successfully registered.

Declaration

public static ObjectName registerMBean(MBeanServer server, String agentName, Map<String, String> attrs,
        Object mbeanObject) throws JMException 

Method Source Code

//package com.java2s;

import java.util.Map;

import javax.management.JMException;

import javax.management.MBeanServer;
import javax.management.ObjectName;

public class Main {
    /**//w w  w .ja  v  a2  s. co m
     * @param server
     * @param agentName
     * @param mbeanType
     * @param mbeanName
     * @param mbeanObject
     * @return The ObjectName of the MBean if successfully registered.
     * 
     * @throws JMException
     */
    public static ObjectName registerMBean(MBeanServer server, String agentName, Map<String, String> attrs,
            Object mbeanObject) throws JMException {
        StringBuilder sb = new StringBuilder(agentName).append(':');
        for (String key : attrs.keySet()) {
            sb.append(key).append('=').append(attrs.get(key)).append(',');
        }

        if (sb.charAt(sb.length() - 1) == ',') {
            sb.deleteCharAt(sb.length() - 1);
        }

        ObjectName oName = new ObjectName(sb.toString());
        if (server.isRegistered(oName)) {
            try {
                server.unregisterMBean(oName);
            } catch (Throwable ignored) {
            }
        }

        server.registerMBean(mbeanObject, oName);
        return oName;
    }
}

Related

  1. paramEquals(MBeanParameterInfo o1, MBeanParameterInfo o2)
  2. queryAndGetAttribute(MBeanServerConnection connection, String domain, String name, String type, String scope, String attribute)
  3. queryConnectionBy(MBeanServerConnection connection, ObjectName objectName)
  4. readAttribute(MBeanServer mbeanServer, String mbeanName, String attributeName)
  5. registerMBean(MBeanServer mbs, Object object, ObjectName name, boolean unreg)
  6. registerMBean(Object bean, MBeanServer mBeanServer, ObjectName objectName)
  7. removeTimerNotification(ObjectName timer, Integer id, MBeanServer server)
  8. resolveServerClassLoader(Map env, MBeanServer mbs)
  9. setQueryExpServer(QueryExp query, MBeanServer toSet)