jdk/src/share/classes/javax/management/monitor/CounterMonitor.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 526 61ba2d5ea9da
child 1581 81388748f694
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public synchronized Number getDerivedGauge(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return (Number) super.getDerivedGauge(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Gets the derived gauge timestamp of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <code>0</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param object the name of the object whose derived gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * timestamp is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return The derived gauge timestamp of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return super.getDerivedGaugeTimeStamp(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Gets the current threshold value of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param object the name of the object whose threshold is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @return The threshold value of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public synchronized Number getThreshold(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // If the counter that is monitored rolls over when it reaches a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // maximum value, then the modulus value needs to be set to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // maximum value. The threshold will then also roll over whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // it strictly exceeds the modulus value. When the threshold rolls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // over, it is reset to the value that was specified through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // latest call to the monitor's setInitThreshold method, before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // any offsets were applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (offset.longValue() > 0L &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            modulus.longValue() > 0L &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            o.getThreshold().longValue() > modulus.longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return initThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return o.getThreshold();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Gets the initial threshold value common to all observed objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return The initial threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see #setInitThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public synchronized Number getInitThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return initThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Sets the initial threshold value common to all observed objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <BR>The current threshold of every object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * observed MBeans is updated consequently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @param value The initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * threshold is null or the threshold value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #getInitThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public synchronized void setInitThreshold(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            throw new IllegalArgumentException("Null threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            throw new IllegalArgumentException("Negative threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (initThreshold.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        initThreshold = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            cmo.setThreshold(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns the derived gauge of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @return The derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * {@link #getDerivedGauge(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public synchronized Number getDerivedGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return (Number) observedObjects.get(0).getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Gets the derived gauge timestamp of the first object in the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @return The derived gauge timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @deprecated As of JMX 1.2, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * {@link #getDerivedGaugeTimeStamp(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public synchronized long getDerivedGaugeTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return observedObjects.get(0).getDerivedGaugeTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Gets the threshold value of the first object in the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return The threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see #setThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @deprecated As of JMX 1.2, replaced by {@link #getThreshold(ObjectName)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public synchronized Number getThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return getThreshold(getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Sets the initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param value The initial threshold value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @exception IllegalArgumentException The specified threshold is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * null or the threshold value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see #getThreshold()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @deprecated As of JMX 1.2, replaced by {@link #setInitThreshold}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public synchronized void setThreshold(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        setInitThreshold(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Gets the offset value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @return The offset value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #setOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public synchronized Number getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Sets the offset value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param value The offset value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * offset is null or the offset value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see #getOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public synchronized void setOffset(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            throw new IllegalArgumentException("Null offset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw new IllegalArgumentException("Negative offset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (offset.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        offset = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Gets the modulus value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @see #setModulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @return The modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public synchronized Number getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return modulus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Sets the modulus value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @param value The modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * modulus is null or the modulus value is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see #getModulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public synchronized void setModulus(Number value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            throw new IllegalArgumentException("Null modulus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (value.longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            throw new IllegalArgumentException("Negative modulus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (modulus.equals(value))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        modulus = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Gets the notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @return <CODE>true</CODE> if the counter monitor notifies when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * exceeding the threshold, <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @see #setNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public synchronized boolean getNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return notify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Sets the notification's on/off switch value common to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param value The notification's on/off switch value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @see #getNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public synchronized void setNotify(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if (notify == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        notify = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * Gets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @return <CODE>true</CODE> if the difference mode is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see #setDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public synchronized boolean getDifferenceMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return differenceMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Sets the difference mode flag value common to all observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @param value The difference mode flag value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @see #getDifferenceMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    public synchronized void setDifferenceMode(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (differenceMode == value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        differenceMode = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                (CounterMonitorObservedObject) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            cmo.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            cmo.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Returns a <CODE>NotificationInfo</CODE> object containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * name of the Java class of the notification and the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * types sent by the counter monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return notifsInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *  PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Updates the derived gauge attribute of the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param scanCounter The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @return <CODE>true</CODE> if the derived gauge value is valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <CODE>false</CODE> otherwise.  The derived gauge value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <CODE>true</CODE> and it is the first notification (so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * haven't 2 consecutive values to update the derived gauge).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    private synchronized boolean updateDerivedGauge(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Object scanCounter, CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        boolean is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        // The counter difference mode is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        if (differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            // The previous scan counter has been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (o.getPreviousScanCounter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                setDerivedGaugeWithDifference((Number)scanCounter, null, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                // If derived gauge is negative it means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                // counter has wrapped around and the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                // threshold needs to be reset to its initial value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                if (((Number)o.getDerivedGauge()).longValue() < 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    if (modulus.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        setDerivedGaugeWithDifference((Number)scanCounter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                                      modulus, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    o.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            // The previous scan counter has not been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            // We cannot update the derived gauge...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                is_derived_gauge_valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            o.setPreviousScanCounter((Number)scanCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        // The counter difference mode is not used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            o.setDerivedGauge((Number)scanCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            is_derived_gauge_valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return is_derived_gauge_valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Updates the notification attribute of the observed object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * and notifies the listeners only once if the notify flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * is set to <CODE>true</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private synchronized MonitorNotification updateNotifications(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        MonitorNotification n = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // Send notification if notify is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        if (!o.getEventAlreadyNotified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                o.getThreshold().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                if (notify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    n = new MonitorNotification(THRESHOLD_VALUE_EXCEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                                this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                                0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                                "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                                o.getThreshold());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                if (!differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    o.setEventAlreadyNotified(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            if (MONITOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                final StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                .append("The notification:")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                .append("\n\tNotification observed object = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                .append(o.getObservedObject())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                .append("\n\tNotification observed attribute = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                .append(getObservedAttribute())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                .append("\n\tNotification threshold level = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                .append(o.getThreshold())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                .append("\n\tNotification derived gauge = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                .append(o.getDerivedGauge())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                .append("\nhas already been sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                        "updateNotifications", strb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Updates the threshold attribute of the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    private synchronized void updateThreshold(CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        // Calculate the new threshold value if the threshold has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        // exceeded and if the offset value is greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            o.getThreshold().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            if (offset.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                // Increment the threshold until its value is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                // than the one for the current derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                long threshold_value = o.getThreshold().longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                while (((Number)o.getDerivedGauge()).longValue() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                       threshold_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    threshold_value += offset.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                // Set threshold attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                switch (o.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    case INTEGER:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   743
                        o.setThreshold(Integer.valueOf((int)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    case BYTE:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   746
                        o.setThreshold(Byte.valueOf((byte)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    case SHORT:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   749
                        o.setThreshold(Short.valueOf((short)threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    case LONG:
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   752
                        o.setThreshold(Long.valueOf(threshold_value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                        // Should never occur...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                        MONITOR_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                                "updateThreshold",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                                "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                // If the counter can wrap around when it reaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                // its maximum and we are not dealing with counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                // differences then we need to reset the threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                // to its initial value too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                if (!differenceMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    if (modulus.longValue() > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        if (o.getThreshold().longValue() >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                            modulus.longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                            o.setModulusExceeded(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                            o.setDerivedGaugeExceeded(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                                (Number) o.getDerivedGauge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                // Threshold value has been modified so we can notify again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                o.setModulusExceeded(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                o.setDerivedGaugeExceeded((Number) o.getDerivedGauge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Sets the derived gauge of the specified observed object when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * differenceMode flag is set to <CODE>true</CODE>.  Integer types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * only are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @param scanCounter The value of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @param mod The counter modulus value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    private synchronized void setDerivedGaugeWithDifference(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        Number scanCounter, Number mod, CounterMonitorObservedObject o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        /* We do the arithmetic using longs here even though the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
           result may end up in a smaller type.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
           l == (byte)l (mod 256) for any long l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
           (byte) ((byte)l1 + (byte)l2) == (byte) (l1 + l2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
           and likewise for subtraction.  So it's the same as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
           we had done the arithmetic in the smaller type.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        long derived =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            scanCounter.longValue() - o.getPreviousScanCounter().longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if (mod != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            derived += modulus.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        switch (o.getType()) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   813
        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
   814
        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
   815
        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
   816
        case LONG: o.setDerivedGauge(Long.valueOf(derived)); break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            // Should never occur...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            MONITOR_LOGGER.logp(Level.FINEST, CounterMonitor.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    "setDerivedGaugeWithDifference",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    "the threshold type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Factory method for ObservedObject creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    ObservedObject createObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        final CounterMonitorObservedObject cmo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            new CounterMonitorObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        cmo.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        cmo.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        cmo.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        cmo.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        return cmo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * This method globally sets the derived gauge type for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * "object" and "attribute" after checking that the type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * supplied observed attribute value is one of the value types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * supported by this monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    synchronized boolean isComparableTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        // Check that the observed attribute is of type "Integer".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            o.setType(INTEGER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        } else if (value instanceof Byte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            o.setType(BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        } else if (value instanceof Short) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            o.setType(SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        } else if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            o.setType(LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    synchronized Comparable<?> getDerivedGaugeFromComparable(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                                  ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                                  String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                                  Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        // Check if counter has wrapped around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        if (o.getModulusExceeded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if (((Number)o.getDerivedGauge()).longValue() <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                o.getDerivedGaugeExceeded().longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    o.setThreshold(initThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    o.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        // Update the derived gauge attributes and check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        // validity of the new value. The derived gauge value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        // is invalid when the differenceMode flag is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        // true and it is the first notification, i.e. we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // haven't got 2 consecutive values to update the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        // derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        o.setDerivedGaugeValid(updateDerivedGauge(value, o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return (Comparable<?>) o.getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    synchronized void onErrorNotification(MonitorNotification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        final CounterMonitorObservedObject o = (CounterMonitorObservedObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            getObservedObject(notification.getObservedObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        // Reset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        o.setModulusExceeded(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        o.setEventAlreadyNotified(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        o.setPreviousScanCounter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    synchronized MonitorNotification buildAlarmNotification(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                               ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                                               Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        // Notify the listeners and update the threshold if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        // the updated derived gauge value is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        final MonitorNotification alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        if (o.getDerivedGaugeValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            alarm = updateNotifications(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            updateThreshold(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            alarm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        return alarm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Tests if the threshold, offset and modulus of the specified observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * object are of the same type as the counter. Only integer types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *   If the optional offset or modulus have not been initialized, their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     *   default value is an Integer object with a value equal to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @param object The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @param attribute The observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @param value The sample value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @return <CODE>true</CODE> if type is the same,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    synchronized boolean isThresholdTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                              String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                              Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        final CounterMonitorObservedObject o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            (CounterMonitorObservedObject) getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        Class<? extends Number> c = classForType(o.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        return (c.isInstance(o.getThreshold()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                isValidForType(offset, c) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                isValidForType(modulus, c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
}