Skip to Main Content
Java Management Extensions
book

Java Management Extensions

by J. Steven Perry
June 2002
Intermediate to advanced content levelIntermediate to advanced
312 pages
9h 18m
English
O'Reilly Media, Inc.
Content preview from Java Management Extensions

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:

  • ObservedObject

  • ObservedAttribute

  • StringToCompare

  • NotifyMatch (must be set to true if a notification is to be sent when the derived gauge matches StringToCompare)

  • NotifyDiffer (must be set to true if a notification is to be sent when the derived gauge differs from StringToCompare)

  • 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"); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JMX: Managing J2EE with Java™ Management Extensions

JMX: Managing J2EE with Java™ Management Extensions

Juha Lindfors
Java™ and JMX: Building Manageable Systems

Java™ and JMX: Building Manageable Systems

Heather Kreger, Ward Harold, Leigh Williamson

Publisher Resources

ISBN: 0596002459Supplemental ContentCatalog PageErrata