Package org.glassfish.admin.amx.util.jmx
Class NotificationListenerBase
- java.lang.Object
-
- org.glassfish.admin.amx.util.jmx.NotificationListenerBase
-
- All Implemented Interfaces:
EventListener,NotificationListener
- Direct Known Subclasses:
MBeanRegistrationListener
public abstract class NotificationListenerBase extends Object implements NotificationListener
Convenience base class for listening for Notifications from one or more MBeans, which may be specified as a specific MBean ObjectName, or an ObjectName pattern. If the ObjectName is a pattern, the list of listenees is dynamically maintained.Caller should call
cleanup()when done, because a listener is maintained on the MBeanServer delegate.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNotificationListenerBase(String name, MBeanServerConnection conn, ObjectName pattern)Calls this( conn, listenTo, null, null ).protectedNotificationListenerBase(String name, MBeanServerConnection conn, ObjectName pattern, NotificationFilter filter)Listen to all MBean(s) which match the pattern 'listenTo'.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckAlive()voidcleanup()Reset everything so that no listening is occuring and all lists are empty.protected MBeanServerConnectiongetConn()Set<ObjectName>getListenees()MBeanServerConnectiongetMBeanServerConnection()NotificationFiltergetNotificationFilter(ObjectName objectName)Get the filter originally specified when constructing this object.booleanisAlive()protected voidlistenToIfMatch(ObjectName objectName)protected voidlistenToMBean(ObjectName objectName)voidstartListening()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.management.NotificationListener
handleNotification
-
-
-
-
Constructor Detail
-
NotificationListenerBase
protected NotificationListenerBase(String name, MBeanServerConnection conn, ObjectName pattern) throws IOException
Calls this( conn, listenTo, null, null ).Instantiating code must call setupListening() in order to initiate listening
- Throws:
IOException
-
NotificationListenerBase
protected NotificationListenerBase(String name, MBeanServerConnection conn, ObjectName pattern, NotificationFilter filter) throws IOException
Listen to all MBean(s) which match the pattern 'listenTo'.Instantiating code must call setupListening() in order to initiate listening
- Parameters:
name- arbitrary name of this listenerconn- the MBeanServerConnection or MBeanServerpattern- an MBean ObjectName, or an ObjectName patternfilter- optional NotificationFilter- Throws:
IOException
-
-
Method Detail
-
listenToMBean
protected void listenToMBean(ObjectName objectName) throws InstanceNotFoundException, IOException
- Throws:
InstanceNotFoundExceptionIOException
-
startListening
public void startListening() throws InstanceNotFoundException, IOException- Throws:
InstanceNotFoundExceptionIOException
-
getNotificationFilter
public final NotificationFilter getNotificationFilter(ObjectName objectName)
Get the filter originally specified when constructing this object.
-
listenToIfMatch
protected void listenToIfMatch(ObjectName objectName) throws IOException, InstanceNotFoundException
- Throws:
IOExceptionInstanceNotFoundException
-
cleanup
public void cleanup()
Reset everything so that no listening is occuring and all lists are empty.
-
getListenees
public Set<ObjectName> getListenees()
- Returns:
- a copy of the MBean currently being listened to.
-
getMBeanServerConnection
public final MBeanServerConnection getMBeanServerConnection()
- Returns:
- the MBeanServerConnection in use.
- Throws:
an- Exception if no longer alive ( isAlive() returns false).
-
getConn
protected final MBeanServerConnection getConn()
-
checkAlive
protected final void checkAlive() throws IOException- Throws:
IOException
-
isAlive
public boolean isAlive()
- Returns:
- true if still listening and the connection is still alive
-
-