Java Reference
In-Depth Information
JMX agents as defined by the JMX specification, you can always use them with
your JMX applications. The next section discusses the final agent service defined
by the JMX specification that must be present in all JMX agents.
12.3 T aking corrective measures
Monitors are typically used to send alerts that inform listeners about critical
events, state changes, and so forth, so that other processes or users can take a par-
ticular action. In chapter 1, we stated that an ideal management environment
would be able to take corrective action on its own (and still inform its listeners
about the triggering event). One way to do this is to subclass a JMX monitor (or
use one) and, upon observing the triggering event, take appropriate action before
involving an outside process via a notification.
To demonstrate this idea, you will do something a little simpler. The Correc-
tiveStringMonitor MBean subclasses the JMX StringMonitor MBean and adds
the functionality that if the observed attribute reaches the “differs” state, a partic-
ular method on a particular MBean will be invoked. This added functionality is
little more than you can accomplish by receiving the monitor notification and
executing a method, but it demonstrates how you can configure an MBean to take
some corrective measures before sending out an alerting notification to a user.
The following code is the CorrectiveStringMonitor MBean. It declares one
additional method that allows users to set the ObjectName value and method
name that should be invoked when the observed String differs:
package jmxbook.ch12;
import javax.management.*;
import javax.management.monitor.*;
public interface CorrectiveStringMonitorMBean extends
StringMonitorMBean
{
public void setExecutableMethodOnDiffer(
ObjectName name, String methodName );
}
Notice that the interface also extends the StringMonitorMBean interface. It does so
to ensure that the CorrectiveStringMonitor MBean includes the management
interface of the StringMonitor MBean. Listing 12.3 shows the MBean class imple-
menting the interface.
Search WWH ::




Custom Search