Java Reference
In-Depth Information
public interface DataLayerMBean
{
public boolean insertData( Object data );
public boolean updateData( Object data );
public boolean deleteData( Object data );
public boolean retrieveData( Object data );
}
The data object should contain enough information for the persistence imple-
mentation to fulfill its task.
The logging MBean
Up to this point, the examples have pertained to Java resources such as proper-
ties and JDBC connections. One example had to do with application configura-
tion, and the other introduced MBeans as components of an application. The
final example of this section combines these concepts.
Most applications use logs to keep records of activity and occurrences of
errors. In many cases, the log file also records developer debug statements for
possible analysis. Like data repositories, logs can be kept in many different
forms, such as a flat file or a database. By writing an MBean, you can both com-
ponentize the application's logging system and expose the logging system to a
management tool. Exposing the logging mechanism allows you to tune it for cer-
tain behavior. For instance, using a management tool, you can tell the logging
MBean to record only critical errors.
By defining the log system as an MBean, you not only encapsulate its implemen-
tation, but also expose it for configuration. The following example creates such
an MBean. First, let's look at its MBean interface, LoggerMBean . As you know, the
interface describes the MBean's exposed attributes and operations:
package jmxbook.ch4;
public interface LoggerMBean
{
public void setLogLevel( int level );
public int getLogLevel();
public String retrieveLog( int linesback );
public void writeLog( String message, int type );
}
Table 4.2 describes the management interface exposed by the LoggerMBean interface.
Search WWH ::




Custom Search