Java Reference
In-Depth Information
Figure 2.2
The
HelloWorld
class
The next section discusses writing both the interface and implementing class
shown in the figure.
2.2.1
Writing the HelloWorld MBean
The first step in developing the
HelloWorld
MBean is to write its Java interface.
The interface declares three methods: one
getter
, one
setter
, and an additional
method for printing the
HelloWorld
MBean's greeting. Normally, you might not
write an interface for a simple HelloWorld example class like this one. However,
as you will learn in chapters 4 and 5,
JMX
uses interfaces to describe the exposed
attributes and operations of an MBean.
Recall that a getter method is a class method with a name in the form of
get-
Member()
, and a setter method is a class method with a name in the form of
set-
Member()
. Think of the methods in a Standard MBean interface as the description
of the implementation class. Put simply, you should be able to understand the
purpose of the methods by their names. In addition, the getter and setter meth-
ods define the member variable access granted to objects that use the MBean. By
creating a getter method for a member variable, you grant
read
access to it. A set-
ter method grants
write
access. As you can see from the following interface, this
MBean is quite simple:
package jmxbook.ch2;
public interface HelloWorldMBean
{
public void setGreeting( String greeting );
public String getGreeting();
public void printGreeting();
}