Java Reference
In-Depth Information
4.2.2
Example: a printer MBean interface
Now that you understand the four major parts of a management interface, let's
look at an example of an MBean interface. Recall that a user-defined MBean
interface indicates that an MBean is a Standard MBean.
The following is the MBean interface for an MBean managing a printer.
Look through it before reading further, and try to determine the attributes and
operations it exposes:
public interface PrinterMBean
{
public int getPrintJobCount();
public String getPrinterName();
public String getPrintQuality();
public void setPrintQuality( int value );
public void cancelPrintJobs();
public void performSelfCheck();
}
The PrinterMBean interface exposes three attributes and two operations. You can
tell this by visually examining the interface. JMX agents use a process called intro-
spection to read the interface. Introspection uses Java reflection to examine the
MBean interface to determine its attributes and operations. After discovering all
the public methods in this interface, the agent uses a small set of rules to deter-
mine what the MBean has exposed as part of its management interface.
To find attributes, a JMX agent looks for any method following the get At-
tributeName () or set AttributeName () naming scheme. In addition to the get At-
tributeName () pattern, you can optionally use the form is AttributeName () ,
which must return a boolean value. However, if an attribute is exposed with a get-
ter method, it cannot also have an is method. Setter methods also have a unique
rule: they cannot be overloaded. For example, this interface would be invalid if
the method setPrintQuality( String value ) was added, because it would
imply that the attribute PrintQuality has two different types: String and int .
WARNING
When you're exposing attributes in a Standard MBean, remember that
Java is case sensitive. For example, the method setPrintQuality()
exposes an attribute PrintQuality , whereas setprintQuality() ex-
poses a different attribute: printQuality .
Table 4.1 breaks down the PrinterMBean interface into the parts of the manage-
ment interface it exposes.
Search WWH ::




Custom Search