Search in sources :

Example 36 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class ManagementFactory method getPlatformMBeanServer.

/**
     * Returns the platform {@link javax.management.MBeanServer MBeanServer}.
     * On the first call to this method, it first creates the platform
     * {@code MBeanServer} by calling the
     * {@link javax.management.MBeanServerFactory#createMBeanServer
     * MBeanServerFactory.createMBeanServer}
     * method and registers each platform MXBean in this platform
     * {@code MBeanServer} with its
     * {@link PlatformManagedObject#getObjectName ObjectName}.
     * This method, in subsequent calls, will simply return the
     * initially created platform {@code MBeanServer}.
     * <p>
     * MXBeans that get created and destroyed dynamically, for example,
     * memory {@link MemoryPoolMXBean pools} and
     * {@link MemoryManagerMXBean managers},
     * will automatically be registered and deregistered into the platform
     * {@code MBeanServer}.
     * <p>
     * If the system property {@code javax.management.builder.initial}
     * is set, the platform {@code MBeanServer} creation will be done
     * by the specified {@link javax.management.MBeanServerBuilder}.
     * <p>
     * It is recommended that this platform MBeanServer also be used
     * to register other application managed beans
     * besides the platform MXBeans.
     * This will allow all MBeans to be published through the same
     * {@code MBeanServer} and hence allow for easier network publishing
     * and discovery.
     * Name conflicts with the platform MXBeans should be avoided.
     *
     * @return the platform {@code MBeanServer}; the platform
     *         MXBeans are registered into the platform {@code MBeanServer}
     *         at the first time this method is called.
     *
     * @exception SecurityException if there is a security manager
     * and the caller does not have the permission required by
     * {@link javax.management.MBeanServerFactory#createMBeanServer}.
     *
     * @see javax.management.MBeanServerFactory
     * @see javax.management.MBeanServerFactory#createMBeanServer
     */
public static synchronized MBeanServer getPlatformMBeanServer() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanServerPermission("createMBeanServer");
        sm.checkPermission(perm);
    }
    if (platformMBeanServer == null) {
        platformMBeanServer = MBeanServerFactory.createMBeanServer();
        for (PlatformComponent pc : PlatformComponent.values()) {
            List<? extends PlatformManagedObject> list = pc.getMXBeans(pc.getMXBeanInterface());
            for (PlatformManagedObject o : list) {
                // before registering into the platform MBeanServer
                if (!platformMBeanServer.isRegistered(o.getObjectName())) {
                    addMXBean(platformMBeanServer, o);
                }
            }
        }
        HashMap<ObjectName, DynamicMBean> dynmbeans = ManagementFactoryHelper.getPlatformDynamicMBeans();
        for (Map.Entry<ObjectName, DynamicMBean> e : dynmbeans.entrySet()) {
            addDynamicMBean(platformMBeanServer, e.getValue(), e.getKey());
        }
        for (final PlatformManagedObject o : ExtendedPlatformComponent.getMXBeans()) {
            if (!platformMBeanServer.isRegistered(o.getObjectName())) {
                addMXBean(platformMBeanServer, o);
            }
        }
    }
    return platformMBeanServer;
}
Also used : ExtendedPlatformComponent(sun.management.ExtendedPlatformComponent) DynamicMBean(javax.management.DynamicMBean) MBeanServerPermission(javax.management.MBeanServerPermission) Permission(java.security.Permission) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServerPermission(javax.management.MBeanServerPermission) ObjectName(javax.management.ObjectName)

Example 37 with DynamicMBean

use of javax.management.DynamicMBean in project ignite by apache.

the class IgniteUtils method registerMBean.

/**
     * Registers MBean with the server.
     *
     * @param <T> Type of mbean.
     * @param mbeanSrv MBean server.
     * @param name MBean object name.
     * @param impl MBean implementation.
     * @param itf MBean interface.
     * @return JMX object name.
     * @throws JMException If MBean creation failed.
     */
public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, ObjectName name, T impl, Class<T> itf) throws JMException {
    assert mbeanSrv != null;
    assert name != null;
    assert itf != null;
    DynamicMBean mbean = new IgniteStandardMXBean(impl, itf);
    mbean.getMBeanInfo();
    return mbeanSrv.registerMBean(mbean, name).getObjectName();
}
Also used : DynamicMBean(javax.management.DynamicMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean)

Aggregations

DynamicMBean (javax.management.DynamicMBean)37 MBeanException (javax.management.MBeanException)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)13 ObjectName (javax.management.ObjectName)10 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 InstanceNotFoundException (javax.management.InstanceNotFoundException)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)8 MalformedObjectNameException (javax.management.MalformedObjectNameException)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)7 NamedObject (com.sun.jmx.mbeanserver.NamedObject)6 ReflectionException (javax.management.ReflectionException)6 JMRuntimeException (javax.management.JMRuntimeException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)4 NotificationListener (javax.management.NotificationListener)4 RuntimeMBeanException (javax.management.RuntimeMBeanException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3