Java Reference
In-Depth Information
adapter to change the values of the target MBean in order to produce events in
the monitoring MBeans.
12.2.1
Creating the example agent and MBean
The first thing you need to do is make the ObservableObject MBean. Remember
that this MBean will be the target of all the monitor MBeans. Your MBean in this
case is a Standard MBean, because it will implement its own MBean interface.
This MBean is designed to be observable by all three types of JMX standard mon-
itors (String, Gauge, and Counter), so you will give it an attribute applicable to
all three types of monitors. Here is the MBean interface for the MBean:
package jmxbook.ch12;
public interface ObservableObjectMBean
{
public String getString();
public void setString( String value );
public Float getGauge();
public void setGauge( Float value );
public Integer getCounter();
public void setCounter( Integer value );
}
As you can tell, this MBean will have three read/write attributes. Each attribute
corresponds to the particular type of monitor that will test it. The initial values
for these attributes will be set through the HTML adapter of the agent.
Listing 12.1 shows the implementing MBean class for the ObservableObject-
MBean . It is a simple class, so we won't examine it too closely. It stores the
attributes passed to the setter methods and returns the attributes through the
getter methods.
Listing 12.1
ObservableObject.java
package jmxbook.ch12;
public class ObservableObject implements ObservableObjectMBean
{
private Integer counter = null;
private Float gauge = null;
private String string = null;
public ObservableObject()
{
counter = new Integer( 0 );
gauge = new Float( 0 );
string = "abc";
}
Search WWH ::




Custom Search