FileDocCategorySizeDatePackage
StringMonitor.javaAPI DocJava SE 6 API13711Tue Jun 10 00:26:16 BST 2008javax.management.monitor

StringMonitor

public class StringMonitor extends Monitor implements StringMonitorMBean
Defines a monitor MBean designed to observe the values of a string attribute.

A string monitor sends notifications as follows:

  • if the attribute value matches the string to compare value, a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_MATCHED match notification} is sent. The notify match flag must be set to true.
    Subsequent matchings of the string to compare values do not cause further notifications unless the attribute value differs from the string to compare value.
  • if the attribute value differs from the string to compare value, a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_DIFFERED differ notification} is sent. The notify differ flag must be set to true.
    Subsequent differences from the string to compare value do not cause further notifications unless the attribute value matches the string to compare value.
version
4.45 11/17/05
author
Sun Microsystems, Inc
since
1.5

Fields Summary
private String
stringToCompare
String to compare with the observed attribute.
The default value is an empty character sequence.
private boolean
notifyMatch
Flag indicating if the string monitor notifies when matching the string to compare.
The default value is set to false.
private boolean
notifyDiffer
Flag indicating if the string monitor notifies when differing from the string to compare.
The default value is set to false.
private static final String[]
types
private static final MBeanNotificationInfo[]
notifsInfo
private static final int
MATCHING
private static final int
DIFFERING
private static final int
MATCHING_OR_DIFFERING
Constructors Summary
public StringMonitor()
Default constructor.


    /*
     * ------------------------------------------
     *  CONSTRUCTORS
     * ------------------------------------------
     */

           
      
        dbgTag = makeDebugTag();
    
Methods Summary
synchronized javax.management.monitor.MonitorNotificationbuildAlarmNotification(javax.management.ObjectName object, java.lang.String attribute, java.lang.Comparable value)

        String type = null;
        String msg = null;
        Object trigger = null;

        final StringMonitorObservedObject o =
            (StringMonitorObservedObject) getObservedObject(object);
        if (o == null)
            return null;

        // Send matching notification if notifyMatch is true.
        // Send differing notification if notifyDiffer is true.
        //
        if (o.getStatus() == MATCHING_OR_DIFFERING) {
            if (o.getDerivedGauge().equals(stringToCompare)) {
                if (notifyMatch) {
                    type = STRING_TO_COMPARE_VALUE_MATCHED;
                    msg = "";
                    trigger = stringToCompare;
                }
                o.setStatus(DIFFERING);
            } else {
                if (notifyDiffer) {
                    type = STRING_TO_COMPARE_VALUE_DIFFERED;
                    msg = "";
                    trigger = stringToCompare;
                }
                o.setStatus(MATCHING);
            }
        } else {
            if (o.getStatus() == MATCHING) {
                if (o.getDerivedGauge().equals(stringToCompare)) {
                    if (notifyMatch) {
                        type = STRING_TO_COMPARE_VALUE_MATCHED;
                        msg = "";
                        trigger = stringToCompare;
                    }
                    o.setStatus(DIFFERING);
                }
            } else if (o.getStatus() == DIFFERING) {
                if (!o.getDerivedGauge().equals(stringToCompare)) {
                    if (notifyDiffer) {
                        type = STRING_TO_COMPARE_VALUE_DIFFERED;
                        msg = "";
                        trigger = stringToCompare;
                    }
                    o.setStatus(MATCHING);
                }
            }
        }

        return new MonitorNotification(type,
                                       this,
                                       0,
                                       0,
                                       msg,
                                       null,
                                       null,
                                       null,
                                       trigger);
    
ObservedObjectcreateObservedObject(javax.management.ObjectName object)
Factory method for ObservedObject creation.

since
1.6

        final StringMonitorObservedObject smo =
            new StringMonitorObservedObject(object);
        smo.setStatus(MATCHING_OR_DIFFERING);
        return smo;
    
public synchronized java.lang.StringgetDerivedGauge(javax.management.ObjectName object)
Gets the derived gauge of the specified object, if this object is contained in the set of observed MBeans, or null otherwise.

param
object the name of the MBean whose derived gauge is required.
return
The derived gauge of the specified object.
since.unbundled
JMX 1.2

        return (String) super.getDerivedGauge(object);
    
public synchronized java.lang.StringgetDerivedGauge()
Returns the derived gauge of the first object in the set of observed MBeans.

return
The derived gauge.
deprecated
As of JMX 1.2, replaced by {@link #getDerivedGauge(ObjectName)}

        if (observedObjects.isEmpty()) {
            return null;
        } else {
            return (String) observedObjects.get(0).getDerivedGauge();
        }
    
public synchronized longgetDerivedGaugeTimeStamp(javax.management.ObjectName object)
Gets the derived gauge timestamp of the specified object, if this object is contained in the set of observed MBeans, or 0 otherwise.

param
object the name of the object whose derived gauge timestamp is to be returned.
return
The derived gauge timestamp of the specified object.
since.unbundled
JMX 1.2

        return super.getDerivedGaugeTimeStamp(object);
    
public synchronized longgetDerivedGaugeTimeStamp()
Gets the derived gauge timestamp of the first object in the set of observed MBeans.

return
The derived gauge timestamp.
deprecated
As of JMX 1.2, replaced by {@link #getDerivedGaugeTimeStamp(ObjectName)}

        if (observedObjects.isEmpty()) {
            return 0;
        } else {
            return observedObjects.get(0).getDerivedGaugeTimeStamp();
        }
    
public javax.management.MBeanNotificationInfo[]getNotificationInfo()
Returns a NotificationInfo object containing the name of the Java class of the notification and the notification types sent by the string monitor.

        return notifsInfo;
    
public synchronized booleangetNotifyDiffer()
Gets the differing notification's on/off switch value common to all observed MBeans.

return
true if the string monitor notifies when differing from the string to compare, false otherwise.
see
#setNotifyDiffer

        return notifyDiffer;
    
public synchronized booleangetNotifyMatch()
Gets the matching notification's on/off switch value common to all observed MBeans.

return
true if the string monitor notifies when matching the string to compare, false otherwise.
see
#setNotifyMatch

        return notifyMatch;
    
public synchronized java.lang.StringgetStringToCompare()
Gets the string to compare with the observed attribute common to all observed MBeans.

return
The string value.
see
#setStringToCompare

        return stringToCompare;
    
synchronized booleanisComparableTypeValid(javax.management.ObjectName object, java.lang.String attribute, java.lang.Comparable value)
Check that the type of the supplied observed attribute value is one of the value types supported by this monitor.

        // Check that the observed attribute is of type "String".
        //
        if (value instanceof String) {
            return true;
        }
        return false;
    
java.lang.StringmakeDebugTag()

        return "StringMonitor";
    
synchronized voidonErrorNotification(javax.management.monitor.MonitorNotification notification)

        final StringMonitorObservedObject o = (StringMonitorObservedObject)
            getObservedObject(notification.getObservedObject());
        if (o == null)
            return;

        // Reset values.
        //
        o.setStatus(MATCHING_OR_DIFFERING);
    
public synchronized voidsetNotifyDiffer(boolean value)
Sets the differing notification's on/off switch value common to all observed MBeans.

param
value The differing notification's on/off switch value.
see
#getNotifyDiffer

        if (notifyDiffer == value)
            return;
        notifyDiffer = value;
    
public synchronized voidsetNotifyMatch(boolean value)
Sets the matching notification's on/off switch value common to all observed MBeans.

param
value The matching notification's on/off switch value.
see
#getNotifyMatch

        if (notifyMatch == value)
            return;
        notifyMatch = value;
    
public synchronized voidsetStringToCompare(java.lang.String value)
Sets the string to compare with the observed attribute common to all observed MBeans.

param
value The string value.
exception
IllegalArgumentException The specified string to compare is null.
see
#getStringToCompare


        if (value == null) {
            throw new IllegalArgumentException("Null string to compare");
        }

        if (stringToCompare.equals(value))
            return;
        stringToCompare = value;

        // Reset values.
        //
        for (ObservedObject o : observedObjects) {
            final StringMonitorObservedObject smo =
                (StringMonitorObservedObject) o;
            smo.setStatus(MATCHING_OR_DIFFERING);
        }
    
public synchronized voidstart()
Starts the string monitor.

        if (isActive()) {
            if (isTraceOn()) {
                trace("start", "the monitor is already active");
            }
            return;
        }
        // Reset values.
        //
        for (ObservedObject o : observedObjects) {
            final StringMonitorObservedObject smo =
                (StringMonitorObservedObject) o;
            smo.setStatus(MATCHING_OR_DIFFERING);
        }
        doStart();
    
public synchronized voidstop()
Stops the string monitor.

        doStop();