Class JMXUtils


  • public final class JMXUtils
    extends Object
    • Method Detail

      • newMBeanProxy

        public static <T> T newMBeanProxy​(MBeanServerConnection conn,
                                          ObjectName objectName,
                                          Class<T> interfaceClass)
        This method allows you to get at a bean registered with the server. Just provide the class of the mbean, the objectName this bean was registered with and the server this bean was registered with.

        The other methods in this class to register beans use ManagementFactory.getPlatformMBeanServer() as the server to register with.

      • registerMBeanCatchAndLogExceptions

        public static void registerMBeanCatchAndLogExceptions​(Object mbean,
                                                              String objectName)
        Simple method to register a bean with the server. The server used is the one returned by ManagementFactory.getPlatformMBeanServer().

        This bean will remain registered until manually unregistered. If you want life-cycle management, use registerMBeanWeakRefPlusCatchAndLogExceptions(Object, Class, String)

      • registerMBeanWeakRefPlusCatchAndLogExceptions

        public static <T> DynamicMBean registerMBeanWeakRefPlusCatchAndLogExceptions​(T mbean,
                                                                                     Class<T> clazz,
                                                                                     String objectName)
        You must retain a reference to the returned DynamicMBean for as long as you wish this bean to be registered.

        Some mbeans have references to some pretty big classes and we have no good way to de-register these beans because these objects don't have good life-cyle management.

        This method will register your mbean with JMX but JMX will hold onto it weakly so the large object may be GC'ed as usual.

        When there is no more reference to the underlying MBean from anywhere else it may be freed. If this happens, the next call to this objectName will fail with an IllegalStateException. When this happens, this objectName will also be unregisterd with unregisterMBeanCatchAndLogExceptions(String)

        Because of the weird JMX naming conventions, this method uses StandardMBean to proxy the bean as a DynamicMBean to get it through the framework

        Returns:
        the DynamicMBean whose lifecycle controls how long this bean is registered. null will be returned if this bean is not regsitered correctly
      • unregisterMBeanCatchAndLogExceptions

        public static void unregisterMBeanCatchAndLogExceptions​(String objectName)
      • getInstanceBeanProxies

        public static <T> Iterable<T> getInstanceBeanProxies​(Class<T> mbeanClazz)
        Returns proxy interfaces to all beans registered to the server implementing the class mbeanClazz.