Java Reference
In-Depth Information
Listing 12.3
CorrectiveStringMonitorMBean.java
package jmxbook.ch12;
import javax.management.*;
import javax.management.monitor.*;
public class CorrectiveStringMonitor extends StringMonitor
implements CorrectiveStringMonitorMBean
{
private ObjectName executeName = null;
private String executeMethod = null;
public CorrectiveStringMonitor()
{
super();
}
public void setExecutableMethodOnDiffer(
ObjectName name, String methodName )
{
this.executeName = name;
this.executeMethod = methodName;
}
public void sendNotification( Notification not )
{
if( not.getType().equals(
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED ) )
{
try
{
server.invoke( executeName, executeMethod, null, null );
}
catch( Exception e )
{
e.printStackTrace();
}
}
B
Override
sendNotification()
to take
corrective step
super.sendNotification( not );
}
}
B
The CorrectiveStringMonitor class overrides its parent's sendNotification()
method in order to watch for the String -differ notification. For this demonstra-
tion, this notification tells the MBean to take its corrective measure. When an
instance of the class notices a notification being sent of the differ type, it invokes
Search WWH ::




Custom Search