src/java.management/share/classes/javax/management/monitor/GaugeMonitor.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: 2624
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: 2624
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: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
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.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import static javax.management.monitor.Monitor.NumericalType.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import static javax.management.monitor.MonitorNotification.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Defines a monitor MBean designed to observe the values of a gauge attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P> A gauge monitor observes an attribute that is continuously
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * variable with time. A gauge monitor sends notifications as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <LI> if the attribute value is increasing and becomes equal to or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * greater than the high threshold value, a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * MonitorNotification#THRESHOLD_HIGH_VALUE_EXCEEDED threshold high
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * notification} is sent. The notify high flag must be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <BR>Subsequent crossings of the high threshold value do not cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * further notifications unless the attribute value becomes equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * or less than the low threshold value.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <LI> if the attribute value is decreasing and becomes equal to or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * less than the low threshold value, a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * MonitorNotification#THRESHOLD_LOW_VALUE_EXCEEDED threshold low
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * notification} is sent. The notify low flag must be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <BR>Subsequent crossings of the low threshold value do not cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * further notifications unless the attribute value becomes equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * or greater than the high threshold value.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * This provides a hysteresis mechanism to avoid repeated triggering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * of notifications when the attribute value makes small oscillations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * around the high or low threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <P> If the gauge difference mode is used, the value of the derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * gauge is calculated as the difference between the observed gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * values for two successive observations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <BR>The derived gauge value (V[t]) is calculated using the following method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <LI>V[t] = gauge[t] - gauge[t-GP]</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * This implementation of the gauge monitor requires the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * attribute to be of the type integer or floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * (<CODE>Byte</CODE>, <CODE>Integer</CODE>, <CODE>Short</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <CODE>Long</CODE>, <CODE>Float</CODE>, <CODE>Double</CODE>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class GaugeMonitor extends Monitor implements GaugeMonitorMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *  PACKAGE CLASSES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static class GaugeMonitorObservedObject extends ObservedObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public GaugeMonitorObservedObject(ObjectName observedObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            super(observedObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public final synchronized boolean getDerivedGaugeValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        public final synchronized void setDerivedGaugeValid(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                                 boolean derivedGaugeValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            this.derivedGaugeValid = derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public final synchronized NumericalType getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        public final synchronized void setType(NumericalType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        public final synchronized Number getPreviousScanGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return previousScanGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        public final synchronized void setPreviousScanGauge(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                  Number previousScanGauge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            this.previousScanGauge = previousScanGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        public final synchronized int getStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public final synchronized void setStatus(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        private boolean derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        private NumericalType type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        private Number previousScanGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        private int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *  PRIVATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Gauge high threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <BR>The default value is a null Integer object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private Number highThreshold = INTEGER_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Gauge low threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <BR>The default value is a null Integer object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private Number lowThreshold = INTEGER_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Flag indicating if the gauge monitor notifies when exceeding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the high threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <BR>The default value is <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private boolean notifyHigh = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Flag indicating if the gauge monitor notifies when exceeding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * the low threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <BR>The default value is <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private boolean notifyLow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Flag indicating if the gauge difference mode is used.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * gauge difference mode is used, the derived gauge is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * difference between two consecutive observed values.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * the derived gauge is directly the value of the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <BR>The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private boolean differenceMode = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final String[] types = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        RUNTIME_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        OBSERVED_OBJECT_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        OBSERVED_ATTRIBUTE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        OBSERVED_ATTRIBUTE_TYPE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        THRESHOLD_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        THRESHOLD_HIGH_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        THRESHOLD_LOW_VALUE_EXCEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static final MBeanNotificationInfo[] notifsInfo = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            "javax.management.monitor.MonitorNotification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            "Notifications sent by the GaugeMonitor MBean")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // Flags needed to implement the hysteresis mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static final int RISING             = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final int FALLING            = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static final int RISING_OR_FALLING  = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public GaugeMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Starts the gauge monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public synchronized void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (isActive()) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   227
            MONITOR_LOGGER.log(Level.TRACE, "the monitor is already active");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            final GaugeMonitorObservedObject gmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                (GaugeMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            gmo.setStatus(RISING_OR_FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            gmo.setPreviousScanGauge(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        doStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Stops the gauge monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public synchronized void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        doStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    // GETTERS AND SETTERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    //--------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Gets the derived gauge of the specified object, if this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * contained in the set of observed MBeans, or <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param object the name of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return The derived gauge of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   260
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public synchronized Number getDerivedGauge(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return (Number) super.getDerivedGauge(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Gets the derived gauge timestamp of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>0</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param object the name of the object whose derived gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * timestamp is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return The derived gauge timestamp of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   276
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return super.getDerivedGaugeTimeStamp(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Returns the derived gauge of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @return The derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * {@link #getDerivedGauge(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public synchronized Number getDerivedGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return (Number) observedObjects.get(0).getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
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
     * Gets the derived gauge timestamp of the first object in the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @return The derived gauge timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * {@link #getDerivedGaugeTimeStamp(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public synchronized long getDerivedGaugeTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return observedObjects.get(0).getDerivedGaugeTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Gets the high threshold value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return The high threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @see #setThresholds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public synchronized Number getHighThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return highThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Gets the low threshold value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return The low threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see #setThresholds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public synchronized Number getLowThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return lowThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Sets the high and the low threshold values common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param highValue The high threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param lowValue The low threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @exception IllegalArgumentException The specified high/low
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * threshold is null or the low threshold is greater than the high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * threshold or the high threshold and the low threshold are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * of the same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see #getHighThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see #getLowThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public synchronized void setThresholds(Number highValue, Number lowValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if ((highValue == null) || (lowValue == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            throw new IllegalArgumentException("Null threshold value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (highValue.getClass() != lowValue.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            throw new IllegalArgumentException("Different type " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                               "threshold values");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (isFirstStrictlyGreaterThanLast(lowValue, highValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                           highValue.getClass().getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            throw new IllegalArgumentException("High threshold less than " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                               "low threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (highThreshold.equals(highValue) && lowThreshold.equals(lowValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        highThreshold = highValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        lowThreshold = lowValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            final GaugeMonitorObservedObject gmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                (GaugeMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            gmo.setStatus(RISING_OR_FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Gets the high notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return <CODE>true</CODE> if the gauge monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * exceeding the high threshold, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #setNotifyHigh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public synchronized boolean getNotifyHigh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return notifyHigh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Sets the high notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @param value The high notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see #getNotifyHigh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public synchronized void setNotifyHigh(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (notifyHigh == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        notifyHigh = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Gets the low notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return <CODE>true</CODE> if the gauge monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * exceeding the low threshold, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see #setNotifyLow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public synchronized boolean getNotifyLow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return notifyLow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Sets the low notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param value The low notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #getNotifyLow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public synchronized void setNotifyLow(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (notifyLow == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        notifyLow = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Gets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return <CODE>true</CODE> if the difference mode is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #setDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public synchronized boolean getDifferenceMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return differenceMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Sets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param value The difference mode flag value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @see #getDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public synchronized void setDifferenceMode(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (differenceMode == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        differenceMode = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            final GaugeMonitorObservedObject gmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                (GaugeMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            gmo.setStatus(RISING_OR_FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            gmo.setPreviousScanGauge(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Returns a <CODE>NotificationInfo</CODE> object containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * name of the Java class of the notification and the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * types sent by the gauge monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   481
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public MBeanNotificationInfo[] getNotificationInfo() {
2613
9e48ff9b5638 6656633: getNotificationInfo methods static mutable
dfuchs
parents: 526
diff changeset
   483
        return notifsInfo.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *  PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Updates the derived gauge attribute of the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param scanGauge The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return <CODE>true</CODE> if the derived gauge value is valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * <CODE>false</CODE> otherwise.  The derived gauge value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * <CODE>true</CODE> and it is the first notification (so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * haven't 2 consecutive values to update the derived gauge).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private synchronized boolean updateDerivedGauge(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        Object scanGauge, GaugeMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        boolean is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // The gauge difference mode is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // The previous scan gauge has been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            if (o.getPreviousScanGauge() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                setDerivedGaugeWithDifference((Number)scanGauge, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            // The previous scan gauge has not been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            // We cannot update the derived gauge...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                is_derived_gauge_valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            o.setPreviousScanGauge((Number)scanGauge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        // The gauge difference mode is not used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            o.setDerivedGauge((Number)scanGauge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Updates the notification attribute of the observed object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * and notifies the listeners only once if the notify flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * is set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private synchronized MonitorNotification updateNotifications(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        GaugeMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        MonitorNotification n = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        // Send high notification if notifyHigh is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        // Send low notification if notifyLow is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (o.getStatus() == RISING_OR_FALLING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (isFirstGreaterThanLast((Number)o.getDerivedGauge(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                       highThreshold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                       o.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                if (notifyHigh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    n = new MonitorNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                            THRESHOLD_HIGH_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                            this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                            highThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                o.setStatus(FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            } else if (isFirstGreaterThanLast(lowThreshold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                              (Number)o.getDerivedGauge(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                              o.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                if (notifyLow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    n = new MonitorNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            THRESHOLD_LOW_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                            this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                            "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                            lowThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                o.setStatus(RISING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            if (o.getStatus() == RISING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                if (isFirstGreaterThanLast((Number)o.getDerivedGauge(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                           highThreshold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                           o.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    if (notifyHigh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        n = new MonitorNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                THRESHOLD_HIGH_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                highThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    o.setStatus(FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            } else if (o.getStatus() == FALLING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (isFirstGreaterThanLast(lowThreshold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                           (Number)o.getDerivedGauge(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                           o.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    if (notifyLow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        n = new MonitorNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                                THRESHOLD_LOW_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                                this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                lowThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    o.setStatus(RISING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Sets the derived gauge when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <CODE>true</CODE>.  Both integer and floating-point types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @param scanGauge The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    private synchronized void setDerivedGaugeWithDifference(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        Number scanGauge, GaugeMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        Number prev = o.getPreviousScanGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        Number der;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        switch (o.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        case INTEGER:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   641
            der = Integer.valueOf(((Integer)scanGauge).intValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   642
                                  ((Integer)prev).intValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        case BYTE:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   645
            der = Byte.valueOf((byte)(((Byte)scanGauge).byteValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   646
                                      ((Byte)prev).byteValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        case SHORT:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   649
            der = Short.valueOf((short)(((Short)scanGauge).shortValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   650
                                        ((Short)prev).shortValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        case LONG:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   653
            der = Long.valueOf(((Long)scanGauge).longValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   654
                               ((Long)prev).longValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        case FLOAT:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   657
            der = Float.valueOf(((Float)scanGauge).floatValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   658
                                ((Float)prev).floatValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        case DOUBLE:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   661
            der = Double.valueOf(((Double)scanGauge).doubleValue() -
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   662
                                 ((Double)prev).doubleValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            // Should never occur...
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   666
            MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        o.setDerivedGauge(der);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Tests if the first specified Number is greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * the last.  Both integer and floating-point types are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @param greater The first Number to compare with the second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @param less The second Number to compare with the first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @param type The number type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @return <CODE>true</CODE> if the first specified Number is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * greater than or equal to the last, <CODE>false</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private boolean isFirstGreaterThanLast(Number greater,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                           Number less,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                           NumericalType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        case INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        case BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        case SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        case LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return (greater.longValue() >= less.longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        case FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        case DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            return (greater.doubleValue() >= less.doubleValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            // Should never occur...
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   699
            MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Tests if the first specified Number is strictly greater than the last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Both integer and floating-point types are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @param greater The first Number to compare with the second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @param less The second Number to compare with the first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param className The number class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @return <CODE>true</CODE> if the first specified Number is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * strictly greater than the last, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    private boolean isFirstStrictlyGreaterThanLast(Number greater,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                                                   Number less,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                                   String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        if (className.equals("java.lang.Integer") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            className.equals("java.lang.Byte") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            className.equals("java.lang.Short") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            className.equals("java.lang.Long")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return (greater.longValue() > less.longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        else if (className.equals("java.lang.Float") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                 className.equals("java.lang.Double")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            return (greater.doubleValue() > less.doubleValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // Should never occur...
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   733
            MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                    "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * Factory method for ObservedObject creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    ObservedObject createObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        final GaugeMonitorObservedObject gmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            new GaugeMonitorObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        gmo.setStatus(RISING_OR_FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        gmo.setPreviousScanGauge(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        return gmo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * This method globally sets the derived gauge type for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * "object" and "attribute" after checking that the type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * supplied observed attribute value is one of the value types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * supported by this monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    synchronized boolean isComparableTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        final GaugeMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            (GaugeMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // Check that the observed attribute is either of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        // "Integer" or "Float".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            o.setType(INTEGER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        } else if (value instanceof Byte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            o.setType(BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        } else if (value instanceof Short) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            o.setType(SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        } else if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            o.setType(LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        } else if (value instanceof Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            o.setType(FLOAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        } else if (value instanceof Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            o.setType(DOUBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    synchronized Comparable<?> getDerivedGaugeFromComparable(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                                  ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                                  String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                                                  Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        final GaugeMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            (GaugeMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        // Update the derived gauge attributes and check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        // validity of the new value. The derived gauge value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // is invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // true and it is the first notification, i.e. we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // haven't got 2 consecutive values to update the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        // derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        o.setDerivedGaugeValid(updateDerivedGauge(value, o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        return (Comparable<?>) o.getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    synchronized void onErrorNotification(MonitorNotification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        final GaugeMonitorObservedObject o = (GaugeMonitorObservedObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            getObservedObject(notification.getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        o.setStatus(RISING_OR_FALLING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        o.setPreviousScanGauge(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    synchronized MonitorNotification buildAlarmNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                               ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        final GaugeMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            (GaugeMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        // Notify the listeners if the updated derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        // gauge value is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        final MonitorNotification alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        if (o.getDerivedGaugeValid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            alarm = updateNotifications(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            alarm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * Tests if the threshold high and threshold low are both of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * same type as the gauge.  Both integer and floating-point types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *   If the optional lowThreshold or highThreshold have not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *   initialized, their default value is an Integer object with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *   a value equal to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @param object The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @param attribute The observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @param value The sample value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @return <CODE>true</CODE> if type is the same,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    synchronized boolean isThresholdTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                              String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                              Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        final GaugeMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            (GaugeMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        Class<? extends Number> c = classForType(o.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        return (isValidForType(highThreshold, c) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                isValidForType(lowThreshold, c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
}