src/java.management/share/classes/javax/management/monitor/StringMonitor.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2613
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2613
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2613
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2613
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2613
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
    29
import java.lang.System.Logger.Level;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import static javax.management.monitor.MonitorNotification.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Defines a monitor MBean designed to observe the values of a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A string monitor sends notifications as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <LI> if the attribute value matches the string to compare value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_MATCHED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      match notification} is sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      The notify match flag must be set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      <BR>Subsequent matchings of the string to compare values do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      cause further notifications unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      the attribute value differs from the string to compare value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <LI> if the attribute value differs from the string to compare value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_DIFFERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      differ notification} is sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      The notify differ flag must be set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      <BR>Subsequent differences from the string to compare value do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      not cause further notifications unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      the attribute value matches the string to compare value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class StringMonitor extends Monitor implements StringMonitorMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *  PACKAGE CLASSES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static class StringMonitorObservedObject extends ObservedObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public StringMonitorObservedObject(ObjectName observedObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            super(observedObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        public final synchronized int getStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public final synchronized void setStatus(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        private int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *  PRIVATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * String to compare with the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <BR>The default value is an empty character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private String stringToCompare = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Flag indicating if the string monitor notifies when matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * the string to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * <BR>The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private boolean notifyMatch = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Flag indicating if the string monitor notifies when differing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * from the string to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <BR>The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private boolean notifyDiffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final String[] types = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        RUNTIME_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        OBSERVED_OBJECT_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        OBSERVED_ATTRIBUTE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        OBSERVED_ATTRIBUTE_TYPE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        STRING_TO_COMPARE_VALUE_MATCHED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        STRING_TO_COMPARE_VALUE_DIFFERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static final MBeanNotificationInfo[] notifsInfo = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            "javax.management.monitor.MonitorNotification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            "Notifications sent by the StringMonitor MBean")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // Flags needed to implement the matching/differing mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final int MATCHING                   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final int DIFFERING                  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final int MATCHING_OR_DIFFERING      = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public StringMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Starts the string monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public synchronized void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (isActive()) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   154
            MONITOR_LOGGER.log(Level.TRACE, "the monitor is already active");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            final StringMonitorObservedObject smo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                (StringMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            smo.setStatus(MATCHING_OR_DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        doStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Stops the string monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public synchronized void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        doStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    // GETTERS AND SETTERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    //--------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Gets the derived gauge of the specified object, if this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * contained in the set of observed MBeans, or <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param object the name of the MBean whose derived gauge is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return The derived gauge of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
2613
9e48ff9b5638 6656633: getNotificationInfo methods static mutable
dfuchs
parents: 2
diff changeset
   186
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public synchronized String getDerivedGauge(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return (String) super.getDerivedGauge(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Gets the derived gauge timestamp of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <code>0</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param object the name of the object whose derived gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * timestamp is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return The derived gauge timestamp of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
2613
9e48ff9b5638 6656633: getNotificationInfo methods static mutable
dfuchs
parents: 2
diff changeset
   202
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return super.getDerivedGaugeTimeStamp(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Returns the derived gauge of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return The derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * {@link #getDerivedGauge(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public synchronized String getDerivedGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return (String) observedObjects.get(0).getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Gets the derived gauge timestamp of the first object in the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return The derived gauge timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * {@link #getDerivedGaugeTimeStamp(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public synchronized long getDerivedGaugeTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return observedObjects.get(0).getDerivedGaugeTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Gets the string to compare with the observed attribute common
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return The string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see #setStringToCompare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public synchronized String getStringToCompare() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return stringToCompare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Sets the string to compare with the observed attribute common
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param value The string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * string to compare is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see #getStringToCompare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public synchronized void setStringToCompare(String value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new IllegalArgumentException("Null string to compare");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (stringToCompare.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        stringToCompare = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            final StringMonitorObservedObject smo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                (StringMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            smo.setStatus(MATCHING_OR_DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Gets the matching notification's on/off switch value common to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @return <CODE>true</CODE> if the string monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * matching the string to compare, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see #setNotifyMatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public synchronized boolean getNotifyMatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return notifyMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Sets the matching notification's on/off switch value common to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param value The matching notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #getNotifyMatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public synchronized void setNotifyMatch(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (notifyMatch == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        notifyMatch = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Gets the differing notification's on/off switch value common to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @return <CODE>true</CODE> if the string monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * differing from the string to compare, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #setNotifyDiffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public synchronized boolean getNotifyDiffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return notifyDiffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Sets the differing notification's on/off switch value common to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param value The differing notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @see #getNotifyDiffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public synchronized void setNotifyDiffer(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (notifyDiffer == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        notifyDiffer = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Returns a <CODE>NotificationInfo</CODE> object containing the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * the Java class of the notification and the notification types sent by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * the string monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
2613
9e48ff9b5638 6656633: getNotificationInfo methods static mutable
dfuchs
parents: 2
diff changeset
   345
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public MBeanNotificationInfo[] getNotificationInfo() {
2613
9e48ff9b5638 6656633: getNotificationInfo methods static mutable
dfuchs
parents: 2
diff changeset
   347
        return notifsInfo.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Factory method for ObservedObject creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    ObservedObject createObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        final StringMonitorObservedObject smo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            new StringMonitorObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        smo.setStatus(MATCHING_OR_DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return smo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Check that the type of the supplied observed attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * value is one of the value types supported by this monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    synchronized boolean isComparableTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // Check that the observed attribute is of type "String".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    synchronized void onErrorNotification(MonitorNotification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        final StringMonitorObservedObject o = (StringMonitorObservedObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            getObservedObject(notification.getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        o.setStatus(MATCHING_OR_DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    synchronized MonitorNotification buildAlarmNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                               ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        String type = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        String msg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        Object trigger = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        final StringMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            (StringMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Send matching notification if notifyMatch is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // Send differing notification if notifyDiffer is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (o.getStatus() == MATCHING_OR_DIFFERING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (o.getDerivedGauge().equals(stringToCompare)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (notifyMatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    type = STRING_TO_COMPARE_VALUE_MATCHED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    trigger = stringToCompare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                o.setStatus(DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (notifyDiffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    type = STRING_TO_COMPARE_VALUE_DIFFERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    trigger = stringToCompare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                o.setStatus(MATCHING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (o.getStatus() == MATCHING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                if (o.getDerivedGauge().equals(stringToCompare)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (notifyMatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        type = STRING_TO_COMPARE_VALUE_MATCHED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        trigger = stringToCompare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    o.setStatus(DIFFERING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            } else if (o.getStatus() == DIFFERING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                if (!o.getDerivedGauge().equals(stringToCompare)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    if (notifyDiffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        type = STRING_TO_COMPARE_VALUE_DIFFERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        trigger = stringToCompare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    o.setStatus(MATCHING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return new MonitorNotification(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                       this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                       0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                       0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                                       msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                       trigger);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}