Java Reference
In-Depth Information
Table 4.2 The parts of the LoggerMBean interface. Attributes are
described by the getter and setter methods, and operations are
described by the remaining methods.
Declared method
Part
Description
Attribute
Declares write access to LogLevel
setLogLevel()
Attribute
Declares read access to LogLevel
getLogLevel()
Operation
Declares an exposed operation
retrieveLog()
Operation
Declares an exposed operation
writeLog()
The Logger class implements the LoggerMBean with a flat-file implementation.
Listing 4.4 shows the Logger class.
Listing 4.4
Logger.java
package jmxbook.ch4;
import javax.management.*;
import java.io.*;
import java.util.*;
public class Logger implements LoggerMBean
{
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;
public Logger()
{
try
{
//open the initial log file
out = new PrintWriter(
new FileOutputStream
( "record.log " ) );
}
catch( Exception e )
{
e.printStackTrace();
}
}
public void setLogLevel( int level )
{
logLevel = level;
}
Search WWH ::




Custom Search