String Monitors
As we mentioned in the beginning of this chapter, a string monitor is used to monitor an MBean attribute that:
Matches a predefined value
Differs from a predefined value
Is of type
String
In this section, we will look at the agent code that shows how to use
a string monitor. When using a string monitor, the first thing to do
is to create a new instance of the StringMonitor
class:
StringMonitor monitor = new StringMonitor( );
After that, the following attributes of the string monitor must be set:
ObservedObjectObservedAttributeStringToCompareNotifyMatch(must be set totrueif a notification is to be sent when the derived gauge matchesStringToCompare)NotifyDiffer(must be set totrueif a notification is to be sent when the derived gauge differs fromStringToCompare)GranularityPeriod
We discussed most of these attributes earlier in this chapter. When
the derived gauge differs from StringToCompare and
NotifyDiffer is set to true, a
difference notification is sent. By the same token, if
StringToCompare matches the derived gauge and
NotifyMatch is set to true, a match notification
is sent. The following example shows how to use both of these
notifications in conjunction to monitor a String
attribute:
try { StringMonitor monitor = new StringMonitor( ); monitor.setObservedObject(new ObjectName("UserDomain:name=Controller")); monitor.setObservedAttribute("OperatorName"); monitor.setNotifyMatch(true); monitor.setNotifyDiffer(true); monitor.setStringToCompare("Unassigned"); ...