Java Reference
In-Depth Information
Create the MBean instance using the appropriate constructor.
1
Invoke the preRegister() method.
2
Register the MBean instance.
3
Invoke the postRegister() method.
4
The postRegister() method is invoked with a Boolean value passed as a parame-
ter. This value indicates whether the registration of the MBean was successful. If
the value is true , registration succeeded. The preRegister() method allows the
MBean to find and use other MBeans. It takes two parameters: an MBeanServer
instance and an ObjectName instance. If the ObjectName parameter is passed as
null, the method should return an appropriate ObjectName value to use with the
registration of this MBean.
Revisiting the Logger MBean, listing 4.5 shows how to implement the MBean-
Registration interface to provide the Logger class with a mechanism to get the
initial values for its attributes. The changes from the previous Logger MBean
class (listing 4.4) are shown in bold.
Listing 4.5
Logger.java
package jmxbook.ch4;
import javax.management.*;
import java.io.*;
import java.util.*;
public class Logger implements LoggerMBean , MBeanRegistration
{
public static final int ALL = 3;
public static final int ERRORS = 2;
public static final int NONE = 1;
private PrintWriter out = null;
private int logLevel = Logger.ALL;
private MBeanServer server = null;
public Logger()
{
try
{
out = new PrintWriter(
new FileOutputStream (
"record.log" ) );
}
catch( Exception e )
{
e.printStackTrace();
Search WWH ::




Custom Search