Java EE 5 SDK

com.sun.appserv.management.util.jmx
Class NotificationListenerBase

java.lang.Object
  extended by com.sun.appserv.management.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
NotificationListenerBase(MBeanServerConnection conn, ObjectName pattern)
          Calls this( conn, listenTo, null, null ).
NotificationListenerBase(MBeanServerConnection conn, ObjectName pattern, NotificationFilter filter)
          Listen to all MBean(s) which match the pattern 'listenTo'
 
Method Summary
protected  void checkAlive()
           
 void cleanup()
          Reset everything so that no listening is occuring and all lists are empty.
protected  MBeanServerConnection getConn()
           
 Set<ObjectName> getListenees()
           
 MBeanServerConnection getMBeanServerConnection()
           
 NotificationFilter getNotificationFilter(ObjectName objectName)
          Get the filter originally specified when constructing this object.
abstract  void handleNotification(Notification notif, Object handback)
          Subclass should implement this routine.
 boolean isAlive()
           
protected  void listenToIfMatch(ObjectName objectName)
           
protected  void listenToMBean(ObjectName objectName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NotificationListenerBase

public NotificationListenerBase(MBeanServerConnection conn,
                                ObjectName pattern)
                         throws InstanceNotFoundException,
                                IOException
Calls this( conn, listenTo, null, null ).

Throws:
InstanceNotFoundException
IOException

NotificationListenerBase

public NotificationListenerBase(MBeanServerConnection conn,
                                ObjectName pattern,
                                NotificationFilter filter)
                         throws InstanceNotFoundException,
                                IOException
Listen to all MBean(s) which match the pattern 'listenTo'

Parameters:
conn - the MBeanServerConnection or MBeanServer
pattern - an MBean ObjectName, or an ObjectName pattern
filter - optional NotificationFilter
Throws:
InstanceNotFoundException
IOException
Method Detail

handleNotification

public abstract void handleNotification(Notification notif,
                                        Object handback)
Subclass should implement this routine.

Specified by:
handleNotification in interface NotificationListener

listenToMBean

protected void listenToMBean(ObjectName objectName)
                      throws InstanceNotFoundException,
                             IOException
Throws:
InstanceNotFoundException
IOException

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:
IOException
InstanceNotFoundException

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

Java EE 5 SDK

Submit a bug or feature

Copyright 2006 Sun Microsystems, Inc. All rights reserved.