Class MBeanListener<T extends MBeanListener.Callback>

  • All Implemented Interfaces:
    java.util.EventListener, javax.management.NotificationListener

    @Taxonomy(stability=UNCOMMITTED)
    public class MBeanListener<T extends MBeanListener.Callback>
    extends java.lang.Object
    implements javax.management.NotificationListener
    Listens for registration of MBeans of various types. Intended usage is for subsystems to lazy-load only when the Parent MBean is registered.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  MBeanListener.Callback
      Callback interface.
      static class  MBeanListener.CallbackImpl
      Default callback implementation, can be subclassed if needed Remembers only the last MBean that was seen.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private T mCallback  
      private java.lang.String mJMXDomain
      listen for MBeans in a given domain of a given type[name] OR an ObjectName (below)
      private javax.management.MBeanServerConnection mMBeanServer  
      private java.lang.String mName  
      private javax.management.ObjectName mObjectName
      mType and mName should be null if mObjectName is non-null, and vice versa
      private java.lang.String mType  
    • Constructor Summary

      Constructors 
      Constructor Description
      MBeanListener​(javax.management.MBeanServerConnection server, java.lang.String domain, java.lang.String type, java.lang.String name, T callback)
      Listener for MBeans of specified type, with specified name (or any name if null is passed for the name).
      MBeanListener​(javax.management.MBeanServerConnection server, java.lang.String domain, java.lang.String type, T callback)
      Listener for all MBeans of specified type, with or without a name.
      MBeanListener​(javax.management.MBeanServerConnection server, javax.management.ObjectName objectName, T callback)
      Listener for a specific MBean.
    • Field Detail

      • mJMXDomain

        private final java.lang.String mJMXDomain
        listen for MBeans in a given domain of a given type[name] OR an ObjectName (below)
      • mType

        private final java.lang.String mType
      • mName

        private final java.lang.String mName
      • mObjectName

        private final javax.management.ObjectName mObjectName
        mType and mName should be null if mObjectName is non-null, and vice versa
      • mMBeanServer

        private final javax.management.MBeanServerConnection mMBeanServer
    • Constructor Detail

      • MBeanListener

        public MBeanListener​(javax.management.MBeanServerConnection server,
                             javax.management.ObjectName objectName,
                             T callback)
        Listener for a specific MBean. Caller must call startListening() to start listening.
        Parameters:
        server -
        objectName -
        callback -
      • MBeanListener

        public MBeanListener​(javax.management.MBeanServerConnection server,
                             java.lang.String domain,
                             java.lang.String type,
                             T callback)
        Listener for all MBeans of specified type, with or without a name. Caller must call startListening() to start listening.
        Parameters:
        server -
        type - type of the MBean (as found in the ObjectName)
        callback -
      • MBeanListener

        public MBeanListener​(javax.management.MBeanServerConnection server,
                             java.lang.String domain,
                             java.lang.String type,
                             java.lang.String name,
                             T callback)
        Listener for MBeans of specified type, with specified name (or any name if null is passed for the name). Caller must call startListening() to start listening.
        Parameters:
        server -
        type - type of the MBean (as found in the ObjectName)
        name - name of the MBean, or null if none
        callback -
    • Method Detail

      • debug

        private static void debug​(java.lang.Object o)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getType

        public java.lang.String getType()
      • getName

        public java.lang.String getName()
      • getMBeanServer

        public javax.management.MBeanServerConnection getMBeanServer()
      • getCallback

        public T getCallback()
      • isRegistered

        private boolean isRegistered​(javax.management.MBeanServerConnection conn,
                                     javax.management.ObjectName objectName)
      • startListening

        public void startListening()
        Start listening. If the required MBean(s) are already present, the callback will be synchronously made before returning. It is also possible that the callback could happen twice for the same MBean.
      • stopListening

        public void stopListening()
        unregister the listener
      • handleNotification

        public void handleNotification​(javax.management.Notification notifIn,
                                       java.lang.Object handback)
        Specified by:
        handleNotification in interface javax.management.NotificationListener