Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

javax.management.event
Class EventSubscriber

java.lang.Object
  extended by javax.management.event.EventSubscriber
All Implemented Interfaces:
EventConsumer

public class EventSubscriber
extends Object
implements EventConsumer

An object that can be used to subscribe for notifications from all MBeans in an MBeanServer that match a pattern. For example, to listen for notifications from all MBeans in the MBeanServer mbs that match com.example:type=Controller,name=* you could write:

 EventSubscriber subscriber = EventSubscriber.getEventSubscriber(mbs);
 ObjectName pattern = new ObjectName("com.example:type=Controller,name=*");
 NotificationListener myListener = ...;
 NotificationFilter myFilter = null;  // or whatever
 Object handback = null;              // or whatever
 subscriber.subscribe(pattern, myListener, myFilter, myHandback);
 


Method Summary
Modifier and Type Method and Description
static EventSubscriber getEventSubscriber(MBeanServer mbs)
          Returns an EventSubscriber object to subscribe for notifications from the given MBeanServer.
 void subscribe(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
          Subscribes a listener to receive events from an MBean or a set of MBeans represented by an ObjectName pattern.
 void unsubscribe(ObjectName name, NotificationListener listener)
          Unsubscribes a listener which is listening to an MBean or a set of MBeans represented by an ObjectName pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEventSubscriber

public static EventSubscriber getEventSubscriber(MBeanServer mbs)
Returns an EventSubscriber object to subscribe for notifications from the given MBeanServer. Calling this method more than once with the same parameter may or may not return the same object.

Parameters:
mbs - the MBeanServer containing MBeans to be subscribed to.
Returns:
An EventSubscriber object.
Throws:
NullPointerException - if mbs is null.

subscribe

public void subscribe(ObjectName name,
                      NotificationListener listener,
                      NotificationFilter filter,
                      Object handback)
               throws IOException
Description copied from interface: EventConsumer

Subscribes a listener to receive events from an MBean or a set of MBeans represented by an ObjectName pattern.

An event emitted by an MBean is forwarded to every listener that was subscribed with the name of that MBean, or with a pattern that matches that name.

Specified by:
subscribe in interface EventConsumer
Parameters:
name - The name of an MBean or an ObjectName pattern representing a set of MBeans to which the listener should listen.
listener - The listener object that will handle the notifications emitted by the MBeans.
filter - The filter object. If filter is null, no filtering will be performed before notification handling.
handback - The context to be sent to the listener when a notification is emitted.
Throws:
IOException - for a remote client, thrown if an I/O error occurs.
See Also:
EventConsumer.unsubscribe(ObjectName, NotificationListener)

unsubscribe

public void unsubscribe(ObjectName name,
                        NotificationListener listener)
                 throws ListenerNotFoundException,
                        IOException
Description copied from interface: EventConsumer

Unsubscribes a listener which is listening to an MBean or a set of MBeans represented by an ObjectName pattern.

The listener to be removed must have been added by the subscribe method with the given name. If the name is a pattern, then the subscribe must have used the same pattern. If the same listener has been subscribed more than once to the name, perhaps with different filters or handbacks, then all such listeners are removed.

Specified by:
unsubscribe in interface EventConsumer
Parameters:
name - The name of the MBean or an ObjectName pattern representing a set of MBeans to which the listener was subscribed.
listener - A listener that was previously subscribed to the MBean(s).
Throws:
ListenerNotFoundException - The given listener was not subscribed to the given name.
IOException - for a remote client, thrown if an I/O error occurs.
See Also:
EventConsumer.subscribe(javax.management.ObjectName, javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

Submit a bug or feature

Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.