Event Service: subscribe to a set of MBeans (registered or non-registered)

Event Service allows to subscribe a listener to a set of MBeans, this simplifies user code by grouping multi requests in one, it also reduces obviously communication between a client and its server.

An MBean to add a listener is usually already registered in an MBeanServer, the Event Service allows to subscribe a listener to a non-registered MBean, or one which will be registered/unregistered time to time. This is very useful, let's see an example:

A manager is monitoring Java VMs running on several hosts, an MBeanServer is running on each host, an VM MBean will be registered to the MBeanServer to represent a new coming VM, the MBean will be unregistered when the VM stops, the ObjectName of a VM MBean starts the fixed ObjectName domain like "vm:". The manager adds a notification listener to each VM MBean to be informed of any change in a VM.

  •  The Event Service allows to register a listener to an MBean without know when the MBean appears:
        ObjectName pattern = new ObjectName("vm:\*");
	eventClient.subscribe(pattern, listener, filter, handback);

Without the Event Service, the manager needs to find a VM MBean himself, there are two things he needs to do:

    1) finding all registered VM MBeans when connecting to an MBeanServer running on a host, this can be done by sending a query request:

        ObjectName pattern = new ObjectName("vm:\*");


	Set<ObjectName> names = hostMBeanServerConnection.getNames(pattern, null);

    and then registering a listener to each found MBean:

	for (ObjectName name : names) {

hostMBeanServerConnection.addNotificationListener(name, listener, filter, handback);

}

 2) registering a special listener to receive MBeanServerNotifications from MBeanServerDelegate, if a received MBeanServerNotifications is about a VM MBean registration, adding a listener to the new registered VM MBean.
Considering that some VM MBeans will come or disappear during 1), the manager should pay attention to not miss any new coming VM MBean or to not add a listener to a VM MBean more than one time. This is not an easy job.

 

  • The Event Service helps avoid missing notifications. After a VM MBean is registered, it may send out immediately notifications. If the manager needs to wait at first an MBeanServerNotifications from MBeanServerDelegate to be informed of a new MBean registration and then add a listener to the MBean, he may miss some notifications sent out before his listener is added. With the Event Service, this problem will not appear if the VM MBean implements the interface MBeanRegistration and ensures to not send out notification before the method MBeanRegistration.postRegister(Boolean registrationDone)) is called. It is always a good practice to not send out notification before MBean registration is finished.


Comments:

[Trackback] Shanliang Jiang talks about one of the main use cases of the Event Service from the new JMX API in <a href="http://blogs.sun.com/shanliang/entry/event_sevice_subscribe_to_a">this blog entry</a>. You can use a wildcard ObjectName to subscribe to a set ...

Posted by Eamonn McManus's Blog on September 19, 2008 at 06:16 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Shanliang Jiang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today