Java Reference
In-Depth Information
Looking over the code for the notification class, you can see that it does not con-
tain anything complex. It declares the three notification types as public static
final member variables for convenience. In addition, it adds methods for setting
and getting a
URL
and an
ObjectInstance
object. The
URL
methods allow the
MLetWrapper
MBean to send the
URL
that was added successfully or that caused
an error. The
ObjectInstance
variable will be set whenever an MBean is created
successfully using the M-let service.
10.4.2
Writing the MLetWrapper MBean
Now that the notification is defined, you can move on to the
MLetWrapper
MBean
class. This MBean is a Standard MBean (look back at chapter 3 for more informa-
tion about Standard MBeans); because you will wrap the M-let service entirely, the
new
MLetWrapper
MBean class will have the same management interface as the
MLet MBean.
The
MLetWrapper
MBean class implements the MBean interface
jmx-
book.ch10.MLetWrapperMBean
. This MBean interface extends the
javax.man-
agement.loading.MLetMBean
interface. Thus an implementing MBean has the
same interface as the M-let service, ensuring that it has the same attributes
and operations.
In addition, the
MLetWrapper
MBean class implements the
MBeanRegistration
interface to interact with the M-let service and extends the
NotificationBroad-
casterSupport
class to provide support for sending notifications.
The following code shows the
MLetWrapperMBean
interface:
package jmxbook. ch10;
import javax.management.loading.*;
public interface MLetWrapperMBean extends MLetMBean
{
}
The
MLetWrapper
MBean will emit notifications for every MBean it creates and
for every
URL
that is added. The basic behavior of the MBean is to delegate all
method calls to the M-let service and capture return values in order to generate
notifications. Listing 10.3 shows the
MLetWrapper
class.
Listing 10.3
MLetWrapper.java
package jmxbook.ch10;
import javax.management.*;
import javax.management.loading.*;