Java Reference
In-Depth Information
see the P olling MBean registered in the agent. From the MBean View, you can
change the interval attribute and execute the start() operation. If you do both,
you should see output something like the following:
jmx.attribute.change
ch6.PollingMBean.counter
ch6.PollingMBean.counter
ch6.PollingMBean.counter
ch6.PollingMBean.counter
The attribute change notification was received when the interval attribute was
altered, and the series of counter notifications was received after the start()
operation was executed.
Writing this setup class also showed you one way of registering for notifica-
tions. The setup class invoked the addNotificationListener() of the MBean
server. In the next section, we will summarize a few more details about register-
ing as a notification listener.
6.5 Registering as a notification listener
If you remember from chapter 2, the HelloAgent class registered itself as a noti-
fication listener when it created the final version of the HelloWorld MBean. In
that class, you used a method from the MBean server to register for notifica-
tions from the MBean. However, that is only one way to register with an MBean
as a listener.
The next two sections describe how to register a listener with an MBean by
using methods from the MBean or methods from the MBean server.
6.5.1
Registering with an MBean
If you have a class that creates an MBean object and registers it on an MBean server
(using the registerMBean() method), then you can invoke methods on the refer-
ence at hand. If the MBean implements the NotificationBroadcaster interface
in order to send notifications, then it also defines a method addNotificationLis-
tener() . Because you have manually created this MBean, you can also invoke its
add listener method to add your own listener.
Notification objects received from an MBean after registering in this man-
ner have their source class member set to contain an actual object reference to
the MBean that emitted the notification. However, this is not the case if you reg-
ister as a listener via the MBean server, as you did in chapter 2.
Search WWH ::




Custom Search