Java Reference
In-Depth Information
B
C
The only constructor of the MLetWrapper MBean accepts an object name String
value that should correspond to an instance of the M-let service already present
in the MBean server at the time of construction. The preRegister() method is
invoked before the MBean will be registered in the MBean server. In this method,
the MLetWrapper MBean attempts to locate the M-let service with the ObjectName
value specified in its constructor.
If the M-let service is not found, the preRegister() method throws an Excep-
tion in order to stop the registration process. The exception will ensure that an
MLetWrapper MBean will not operate without an M-let service in the agent.
Instead of throwing an Exception when it doesn't find an M-let service, the
MBean could tell the MBean server to create one.
The getMBeansFromURL( URL url ) method provides a pattern for the methods
that emit notifications ( getMBeansFromURL() and addURL() ). This method can
emit one of two possible notification types represented by the public final static
variables MLetNotification.MBEAN_TYPE and MLetNotification.ERROR_TYPE . The
method delegates the work to the M-let service MBean and, depending on the
result, sends either a success-type notification or an error-type notification.
If the method succeeds, it builds an MLetNotification with the returned Set
of ObjectInstance objects and the URL that was specified as a parameter. For any
error, including exceptions thrown while working with the MBean server, the
getMBeansFromURL() method emits a notification populated with an error type
and the URL specified in the incoming parameter.
The getURLs() method demonstrates how the remaining methods are imple-
mented. They do not emit notifications—they only delegate the method call to
the M-let service and return the result where appropriate. In addition, these
methods capture any exception arising from the interaction with the MBean
server. If an exception is thrown by the MBean server, each method simply
catches it and returns (null where appropriate).
D
E
10.4.3
Using the MLetWrapper MBean
To register for notifications, you need to create and register the new MLetWrapper
MBean. However, instead of using the HTML adapter as you did for the examples
in section 10.3, you will write a setup class to register the new wrapper MBean in
your agent. Listing 10.4 shows the MLetWrapperSetup class. This class will use the
RMIClientFactory class from chapter 3 to contact the agent and create an instance
of the MLetWrapper MBean. It also adds itself as a notification listener.
Search WWH ::




Custom Search