Here you can find the source of registerMBean(MBeanServer server, String agentName, Map
Parameter | Description |
---|---|
server | a parameter |
agentName | a parameter |
mbeanType | a parameter |
mbeanName | a parameter |
mbeanObject | a parameter |
Parameter | Description |
---|---|
JMException | an exception |
public static ObjectName registerMBean(MBeanServer server, String agentName, Map<String, String> attrs, Object mbeanObject) throws JMException
//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; } }