org.glassfish.external.amx
Class MBeanListener<T extends MBeanListener.Callback>

java.lang.Object
  extended by org.glassfish.external.amx.MBeanListener<T>
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
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.
 
Constructor Summary
MBeanListener(javax.management.MBeanServerConnection server, javax.management.ObjectName objectName, T callback)
          Listener for a specific MBean.
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.
 
Method Summary
 T getCallback()
           
 javax.management.MBeanServerConnection getMBeanServer()
           
 java.lang.String getName()
           
 java.lang.String getType()
           
 void handleNotification(javax.management.Notification notifIn, java.lang.Object handback)
           
 void startListening()
          Start listening.
 void stopListening()
          unregister the listener
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MBeanListener

public MBeanListener(javax.management.MBeanServerConnection server,
                     javax.management.ObjectName objectName,
                     T callback)
Listener for a specific MBean. Caller must call #start 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 #start 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 #start 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

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()

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