JMX-Tiered Architecture
JMX is based on a three-tier architecture that encourages plug-and-play integration for JMX components. Figure 1 shows a diagram of the JMX architecture:

Figure 1: The JMX Architecture
The standard relationship between the manager (protocol adapter, another MBean, etc.), the JMX agent and the managed resource can be seen in Figure 2:

Figure 2: The Manager/JMX Agent/Managed Resource Communication Flow
Creating a Standard MBean
Before you can manage a resource, you have to develop its instrumentation. This means you need to write the corresponding MBean class. The example case in this article exposes static information, which calls for a standard MBean. To write a correct standard MBean, you have to keep in mind the following 11 golden rules:
- An MBean cannot be an abstract class.
- An MBean must have at least one public constructor.
- An MBean must implement an interface that represents the MBean.
- The MBean interface name must follow the correct naming convention:
{MBean class name}MBean.
- MBean attributes can be of type read/write.
- Attributes may have any Java type, including array.
- An attribute of type
read must have a method of type get{attribute name} where the attribute name starts with an upper case letter.
- An attribute of type
write must have a method of type set{attribute name} where the attribute name starts with an upper case letter.
- In the case of a boolean attribute, you can use a method of type
is{attribute name} where the attribute name starts with an upper case letter.
- Attributes names cannot be overloaded.
- Methods that do not represent attributes are known and exposed as operations.
The operations are:
-
startProcess (*): This operation starts the process
-
stopProcess (*): This operation stops the process
-
haltProcess (*): This operation sets stand by on/off, low power, and restarts the process
-
destroyProcess: This operation destroys the process
The attributes and operations you need to expose are marked by (*). The rest are additional attributes/operations that are not available to JMX. In the MBean, the interface will show only the exposed attributes/operations, as you can see below:
public interface MyProcessMBean {
public String getProcessName();
public String getProcessMask();
public boolean isProcessRunning();
public String getProcessHost();
public void setProcessPort(int port);
public int getProcessPort();
public void startProcess();
public void stopProcess();
public void haltProcess(Integer halt);
}
Next, you'll implement this interface into an MBean, as shown in Listing 1.
Now, that you've got your MBean, it's time to test it!
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|