jdk/src/share/classes/javax/management/monitor/CounterMonitor.java
author dfuchs
Fri, 14 Nov 2008 17:22:10 +0100
changeset 1581 81388748f694
parent 715 f16baef3a20e
child 2624 1ae5a9028dd4
permissions -rw-r--r--
6683213: CounterMonitor's derived Gauge badly initialized Reviewed-by: emcmanus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 526
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.logging.Level;
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.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 counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <P> A counter monitor sends a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * MonitorNotification#THRESHOLD_VALUE_EXCEEDED threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * notification} when the value of the counter reaches or exceeds a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * threshold known as the comparison level.  The notify flag must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <P> In addition, an offset mechanism enables particular counting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * intervals to be detected.  If the offset value is not zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * whenever the threshold is triggered by the counter value reaching a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * comparison level, that comparison level is incremented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * offset value.  This is regarded as taking place instantaneously,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * that is, before the count is incremented.  Thus, for each level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the threshold triggers an event notification every time the count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * increases by an interval equal to the offset value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <P> If the counter can wrap around its maximum value, the modulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * needs to be specified.  The modulus is the value at which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * counter is reset to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <P> If the counter difference mode is used, the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * derived gauge is calculated as the difference between the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * counter values for two successive observations.  If this difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * is negative, the value of the derived gauge is incremented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * value of the modulus.  The derived gauge value (V[t]) is calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * using the following method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <LI>if (counter[t] - counter[t-GP]) is positive then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * V[t] = counter[t] - counter[t-GP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <LI>if (counter[t] - counter[t-GP]) is negative then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * V[t] = counter[t] - counter[t-GP] + MODULUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * This implementation of the counter monitor requires the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * attribute to be of the type integer (<CODE>Byte</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <CODE>Integer</CODE>, <CODE>Short</CODE>, <CODE>Long</CODE>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class CounterMonitor extends Monitor implements CounterMonitorMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *  PACKAGE CLASSES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    static class CounterMonitorObservedObject extends ObservedObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public CounterMonitorObservedObject(ObjectName observedObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            super(observedObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public final synchronized Number getThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public final synchronized void setThreshold(Number threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            this.threshold = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        public final synchronized Number getPreviousScanCounter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return previousScanCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        public final synchronized void setPreviousScanCounter(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                                  Number previousScanCounter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            this.previousScanCounter = previousScanCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public final synchronized boolean getModulusExceeded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return modulusExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public final synchronized void setModulusExceeded(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                                 boolean modulusExceeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.modulusExceeded = modulusExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        public final synchronized Number getDerivedGaugeExceeded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return derivedGaugeExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        public final synchronized void setDerivedGaugeExceeded(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                 Number derivedGaugeExceeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            this.derivedGaugeExceeded = derivedGaugeExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        public final synchronized boolean getDerivedGaugeValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            return derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        public final synchronized void setDerivedGaugeValid(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                                 boolean derivedGaugeValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            this.derivedGaugeValid = derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        public final synchronized boolean getEventAlreadyNotified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return eventAlreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        public final synchronized void setEventAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                               boolean eventAlreadyNotified) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            this.eventAlreadyNotified = eventAlreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        public final synchronized NumericalType getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public final synchronized void setType(NumericalType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        private Number threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        private Number previousScanCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        private boolean modulusExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        private Number derivedGaugeExceeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        private boolean derivedGaugeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        private boolean eventAlreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        private NumericalType type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *  PRIVATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Counter modulus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <BR>The default value is a null Integer object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private Number modulus = INTEGER_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Counter offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <BR>The default value is a null Integer object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private Number offset = INTEGER_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Flag indicating if the counter monitor notifies when exceeding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * the threshold.  The default value is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private boolean notify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Flag indicating if the counter difference mode is used.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * counter difference mode is used, the derived gauge is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * difference between two consecutive observed values.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * the derived gauge is directly the value of the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * attribute.  The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private boolean differenceMode = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Initial counter threshold.  This value is used to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * the threshold when a new object is added to the list and reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * the threshold to its initial value each time the counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * resets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private Number initThreshold = INTEGER_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final String[] types = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        RUNTIME_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        OBSERVED_OBJECT_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        OBSERVED_ATTRIBUTE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        OBSERVED_ATTRIBUTE_TYPE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        THRESHOLD_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        THRESHOLD_VALUE_EXCEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final MBeanNotificationInfo[] notifsInfo = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            "javax.management.monitor.MonitorNotification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            "Notifications sent by the CounterMonitor MBean")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    };
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
     *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public CounterMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
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
     *  PUBLIC METHODS
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Starts the counter monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public synchronized void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    "start", "the monitor is already active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            cmo.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            cmo.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        doStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Stops the counter monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public synchronized void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        doStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    // GETTERS AND SETTERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    //--------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Gets the derived gauge of the specified object, if this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * contained in the set of observed MBeans, or <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param object the name of the object whose derived gauge is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return The derived gauge of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   268
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public synchronized Number getDerivedGauge(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return (Number) super.getDerivedGauge(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Gets the derived gauge timestamp of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>0</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param object the name of the object whose derived gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * timestamp is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @return The derived gauge timestamp of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   284
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return super.getDerivedGaugeTimeStamp(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Gets the current threshold value of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param object the name of the object whose threshold is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return The threshold value of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public synchronized Number getThreshold(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // If the counter that is monitored rolls over when it reaches a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // maximum value, then the modulus value needs to be set to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // maximum value. The threshold will then also roll over whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // it strictly exceeds the modulus value. When the threshold rolls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // over, it is reset to the value that was specified through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // latest call to the monitor's setInitThreshold method, before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // any offsets were applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (offset.longValue() > 0L &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            modulus.longValue() > 0L &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            o.getThreshold().longValue() > modulus.longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return initThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return o.getThreshold();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Gets the initial threshold value common to all observed objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return The initial threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see #setInitThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public synchronized Number getInitThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return initThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Sets the initial threshold value common to all observed objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <BR>The current threshold of every object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * observed MBeans is updated consequently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param value The initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * threshold is null or the threshold value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see #getInitThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public synchronized void setInitThreshold(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            throw new IllegalArgumentException("Null threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            throw new IllegalArgumentException("Negative threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (initThreshold.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        initThreshold = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            cmo.setThreshold(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Returns the derived gauge of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return The derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * {@link #getDerivedGauge(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public synchronized Number getDerivedGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return (Number) observedObjects.get(0).getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Gets the derived gauge timestamp of the first object in the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @return The derived gauge timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * {@link #getDerivedGaugeTimeStamp(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public synchronized long getDerivedGaugeTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            return observedObjects.get(0).getDerivedGaugeTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Gets the threshold value of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return The threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see #setThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @deprecated As of JMX 1.2, replaced by {@link #getThreshold(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public synchronized Number getThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return getThreshold(getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Sets the initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @param value The initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @exception IllegalArgumentException The specified threshold is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * null or the threshold value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #getThreshold()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @deprecated As of JMX 1.2, replaced by {@link #setInitThreshold}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public synchronized void setThreshold(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        setInitThreshold(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Gets the offset value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return The offset value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see #setOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public synchronized Number getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Sets the offset value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param value The offset value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * offset is null or the offset value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #getOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public synchronized void setOffset(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            throw new IllegalArgumentException("Null offset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            throw new IllegalArgumentException("Negative offset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (offset.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        offset = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
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
     * Gets the modulus value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @see #setModulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @return The modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public synchronized Number getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return modulus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Sets the modulus value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @param value The modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * modulus is null or the modulus value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see #getModulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public synchronized void setModulus(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            throw new IllegalArgumentException("Null modulus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            throw new IllegalArgumentException("Negative modulus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (modulus.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        modulus = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Gets the notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @return <CODE>true</CODE> if the counter monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * exceeding the threshold, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see #setNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public synchronized boolean getNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return notify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * Sets the notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param value The notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @see #getNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public synchronized void setNotify(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (notify == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        notify = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Gets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @return <CODE>true</CODE> if the difference mode is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @see #setDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public synchronized boolean getDifferenceMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return differenceMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Sets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @param value The difference mode flag value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @see #getDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    public synchronized void setDifferenceMode(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (differenceMode == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        differenceMode = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            cmo.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            cmo.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Returns a <CODE>NotificationInfo</CODE> object containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * name of the Java class of the notification and the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * types sent by the counter monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 715
diff changeset
   600
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return notifsInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *  PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Updates the derived gauge attribute of the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param scanCounter The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @return <CODE>true</CODE> if the derived gauge value is valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <CODE>false</CODE> otherwise.  The derived gauge value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <CODE>true</CODE> and it is the first notification (so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * haven't 2 consecutive values to update the derived gauge).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    private synchronized boolean updateDerivedGauge(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        Object scanCounter, CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        boolean is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // The counter difference mode is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            // The previous scan counter has been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            if (o.getPreviousScanCounter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                setDerivedGaugeWithDifference((Number)scanCounter, null, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                // If derived gauge is negative it means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                // counter has wrapped around and the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                // threshold needs to be reset to its initial value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                if (((Number)o.getDerivedGauge()).longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    if (modulus.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                        setDerivedGaugeWithDifference((Number)scanCounter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                                      modulus, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                    o.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            // The previous scan counter has not been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            // We cannot update the derived gauge...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                is_derived_gauge_valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            o.setPreviousScanCounter((Number)scanCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // The counter difference mode is not used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            o.setDerivedGauge((Number)scanCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Updates the notification attribute of the observed object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * and notifies the listeners only once if the notify flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * is set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    private synchronized MonitorNotification updateNotifications(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        MonitorNotification n = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // Send notification if notify is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        if (!o.getEventAlreadyNotified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            if (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                o.getThreshold().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                if (notify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    n = new MonitorNotification(THRESHOLD_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                                this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                                "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                                o.getThreshold());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                if (!differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    o.setEventAlreadyNotified(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            if (MONITOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                final StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                .append("The notification:")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                .append("\n\tNotification observed object = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                .append(o.getObservedObject())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                .append("\n\tNotification observed attribute = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                .append(getObservedAttribute())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                .append("\n\tNotification threshold level = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                .append(o.getThreshold())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                .append("\n\tNotification derived gauge = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                .append(o.getDerivedGauge())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                .append("\nhas already been sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                        "updateNotifications", strb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Updates the threshold attribute of the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    private synchronized void updateThreshold(CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        // Calculate the new threshold value if the threshold has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        // exceeded and if the offset value is greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            o.getThreshold().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (offset.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                // Increment the threshold until its value is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                // than the one for the current derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                long threshold_value = o.getThreshold().longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                while (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                       threshold_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    threshold_value += offset.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                // Set threshold attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                switch (o.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    case INTEGER:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   746
                        o.setThreshold(Integer.valueOf((int)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    case BYTE:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   749
                        o.setThreshold(Byte.valueOf((byte)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    case SHORT:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   752
                        o.setThreshold(Short.valueOf((short)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    case LONG:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   755
                        o.setThreshold(Long.valueOf(threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                        // Should never occur...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        MONITOR_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                "updateThreshold",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                // If the counter can wrap around when it reaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                // its maximum and we are not dealing with counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                // differences then we need to reset the threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                // to its initial value too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                if (!differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    if (modulus.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        if (o.getThreshold().longValue() >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                            modulus.longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                            o.setModulusExceeded(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                            o.setDerivedGaugeExceeded(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                (Number) o.getDerivedGauge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                // Threshold value has been modified so we can notify again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                o.setModulusExceeded(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                o.setDerivedGaugeExceeded((Number) o.getDerivedGauge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Sets the derived gauge of the specified observed object when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * differenceMode flag is set to <CODE>true</CODE>.  Integer types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * only are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @param scanCounter The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param mod The counter modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    private synchronized void setDerivedGaugeWithDifference(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        Number scanCounter, Number mod, CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        /* We do the arithmetic using longs here even though the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
           result may end up in a smaller type.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
           l == (byte)l (mod 256) for any long l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
           (byte) ((byte)l1 + (byte)l2) == (byte) (l1 + l2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
           and likewise for subtraction.  So it's the same as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
           we had done the arithmetic in the smaller type.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        long derived =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            scanCounter.longValue() - o.getPreviousScanCounter().longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (mod != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            derived += modulus.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        switch (o.getType()) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   816
        case INTEGER: o.setDerivedGauge(Integer.valueOf((int) derived)); break;
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   817
        case BYTE: o.setDerivedGauge(Byte.valueOf((byte) derived)); break;
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   818
        case SHORT: o.setDerivedGauge(Short.valueOf((short) derived)); break;
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   819
        case LONG: o.setDerivedGauge(Long.valueOf(derived)); break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            // Should never occur...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            MONITOR_LOGGER.logp(Level.FINEST, CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    "setDerivedGaugeWithDifference",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Factory method for ObservedObject creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    ObservedObject createObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            new CounterMonitorObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        cmo.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        cmo.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return cmo;
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
     * This method globally sets the derived gauge type for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * "object" and "attribute" after checking that the type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * supplied observed attribute value is one of the value types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * supported by this monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    synchronized boolean isComparableTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        // Check that the observed attribute is of type "Integer".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            o.setType(INTEGER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        } else if (value instanceof Byte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            o.setType(BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        } else if (value instanceof Short) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            o.setType(SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        } else if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            o.setType(LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    synchronized Comparable<?> getDerivedGaugeFromComparable(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                                  ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                                                  String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                                  Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        // Check if counter has wrapped around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        if (o.getModulusExceeded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (((Number)o.getDerivedGauge()).longValue() <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                o.getDerivedGaugeExceeded().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                    o.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    o.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        // Update the derived gauge attributes and check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // validity of the new value. The derived gauge value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        // is invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // true and it is the first notification, i.e. we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        // haven't got 2 consecutive values to update the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        // derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        o.setDerivedGaugeValid(updateDerivedGauge(value, o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        return (Comparable<?>) o.getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    synchronized void onErrorNotification(MonitorNotification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        final CounterMonitorObservedObject o = (CounterMonitorObservedObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            getObservedObject(notification.getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        o.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        o.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    synchronized MonitorNotification buildAlarmNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                                               ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        // Notify the listeners and update the threshold if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        // the updated derived gauge value is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        final MonitorNotification alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (o.getDerivedGaugeValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            alarm = updateNotifications(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            updateThreshold(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            alarm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * Tests if the threshold, offset and modulus of the specified observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * object are of the same type as the counter. Only integer types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *   If the optional offset or modulus have not been initialized, their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *   default value is an Integer object with a value equal to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @param object The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @param attribute The observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @param value The sample value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @return <CODE>true</CODE> if type is the same,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    synchronized boolean isThresholdTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                              String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                              Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        Class<? extends Number> c = classForType(o.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        return (c.isInstance(o.getThreshold()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                isValidForType(offset, c) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                isValidForType(modulus, c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
}