KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > GaugeStatisticMonitor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * GaugeStatisticMonitor.java
26  *
27  * Created on July 11, 2005 3:00 PM
28  */

29
30 package com.sun.enterprise.admin.selfmanagement.event;
31
32 import javax.management.MBeanNotificationInfo JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import static com.sun.enterprise.admin.selfmanagement.event.StatisticMonitor.NumericalType.*;
35 import com.sun.appserv.management.event.StatisticMonitorNotification;
36 import static com.sun.appserv.management.event.StatisticMonitorNotification.*;
37 import java.util.logging.Logger JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import com.sun.logging.LogDomains;
40
41 /**
42  * Defines a monitor MBean designed to observe the values
43  * of a gauge attribute. Used for JDK version greater than 1.5.
44  *
45  * <P> A gauge statistic monitor observes an attribute that is continuously
46  * variable with time. A gauge statistic monitor sends notifications as
47  * follows:
48  *
49  * <UL>
50  *
51  * <LI> if the attribute value is increasing and becomes equal to or
52  * greater than the high threshold value, a {@link
53  * StatisticMonitorNotification#THRESHOLD_HIGH_VALUE_EXCEEDED threshold high
54  * notification} is sent. The notify high flag must be set to
55  * <CODE>true</CODE>.
56  *
57  * <BR>Subsequent crossings of the high threshold value do not cause
58  * further notifications unless the attribute value becomes equal to
59  * or less than the low threshold value.</LI>
60  *
61  * <LI> if the attribute value is decreasing and becomes equal to or
62  * less than the low threshold value, a {@link
63  * StatisticMonitorNotification#THRESHOLD_LOW_VALUE_EXCEEDED threshold low
64  * notification} is sent. The notify low flag must be set to
65  * <CODE>true</CODE>.
66  *
67  * <BR>Subsequent crossings of the low threshold value do not cause
68  * further notifications unless the attribute value becomes equal to
69  * or greater than the high threshold value.</LI>
70  *
71  * </UL>
72  *
73  * This provides a hysteresis mechanism to avoid repeated triggering
74  * of notifications when the attribute value makes small oscillations
75  * around the high or low threshold value.
76  *
77  * <P> If the gauge difference mode is used, the value of the derived
78  * gauge is calculated as the difference between the observed gauge
79  * values for two successive observations.
80  *
81  * <BR>The derived gauge value (V[t]) is calculated using the following method:
82  * <UL>
83  * <LI>V[t] = gauge[t] - gauge[t-GP]</LI>
84  * </UL>
85  *
86  * This implementation of the gauge statistic monitor requires the observed
87  * attribute to be of the type integer or floating-point
88  * (<CODE>Byte</CODE>, <CODE>Integer</CODE>, <CODE>Short</CODE>,
89  * <CODE>Long</CODE>, <CODE>Float</CODE>, <CODE>Double</CODE>).
90  *
91  * @author Sun Microsystems, Inc
92  */

93 public class GaugeStatisticMonitor extends StatisticMonitor implements GaugeStatisticMonitorMBean {
94
95     /*
96      * ------------------------------------------
97      * PRIVATE VARIABLES
98      * ------------------------------------------
99      */

100
101     /**
102      * Gauge high threshold.
103      *
104      * <BR>The default value is a null Integer object.
105      */

106     private Number JavaDoc highThreshold = INTEGER_ZERO;
107
108     /**
109      * Gauge low threshold.
110      *
111      * <BR>The default value is a null Integer object.
112      */

113     private Number JavaDoc lowThreshold = INTEGER_ZERO;
114
115     /**
116      * Flag indicating if the gauge statistic monitor notifies when exceeding
117      * the high threshold.
118      *
119      * <BR>The default value is <CODE>false</CODE>.
120      */

121     private boolean notifyHigh = false;
122
123     /**
124      * Flag indicating if the gauge statistic monitor notifies when exceeding
125      * the low threshold.
126      *
127      * <BR>The default value is <CODE>false</CODE>.
128      */

129     private boolean notifyLow = false;
130
131     /**
132      * Flag indicating if the gauge difference mode is used. If the
133      * gauge difference mode is used, the derived gauge is the
134      * difference between two consecutive observed values. Otherwise,
135      * the derived gauge is directly the value of the observed
136      * attribute.
137      *
138      * <BR>The default value is set to <CODE>false</CODE>.
139      */

140     private boolean differenceMode = false;
141
142     /**
143      * Scan gauge values captured by the previous observation.
144      * <BR>Each element in this array corresponds to an observed
145      * object in the list.
146      */

147     private Number JavaDoc previousScanGauge[] = new Number JavaDoc[capacityIncrement];
148
149     /**
150      * This attribute is used to handle the hysteresis mechanism.
151      * <BR>Each element in this array corresponds to an observed
152      * object in the list.
153      */

154     private int status[] = new int[capacityIncrement];
155
156     /**
157      * This attribute is used to keep the derived gauge type.
158      * <BR>Each element in this array corresponds to an observed
159      * object in the list.
160      */

161     private NumericalType type[] = new NumericalType[capacityIncrement];
162
163     /**
164      * Derived gauge valid.
165      * <BR>Each element in this array corresponds to an observed
166      * object in the list.
167      */

168     private boolean derivedGaugeValid[] = new boolean[capacityIncrement];
169
170     private static final String JavaDoc[] types = {
171         RUNTIME_ERROR,
172         OBSERVED_OBJECT_ERROR,
173         OBSERVED_ATTRIBUTE_ERROR,
174         OBSERVED_ATTRIBUTE_TYPE_ERROR,
175         THRESHOLD_ERROR,
176         THRESHOLD_HIGH_VALUE_EXCEEDED,
177         THRESHOLD_LOW_VALUE_EXCEEDED
178     };
179
180     private static final MBeanNotificationInfo JavaDoc[] notifsInfo = {
181         new MBeanNotificationInfo JavaDoc(
182             types,
183             "com.sun.appserv.management.event.StatisticMonitorNotification",
184             "Notifications sent by the GaugeStatisticMonitor MBean")
185     };
186
187     // Flags needed to implement the hysteresis mechanism.
188
//
189
private static final int RISING = 0;
190     private static final int FALLING = 1;
191     private static final int RISING_OR_FALLING = 2;
192
193     // LOGGER
194
//---------------
195
protected static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER);
196
197
198     /*
199      * ------------------------------------------
200      * CONSTRUCTORS
201      * ------------------------------------------
202      */

203
204     /**
205      * Default constructor.
206      */

207     public GaugeStatisticMonitor() {
208     }
209
210     /*
211      * ------------------------------------------
212      * PUBLIC METHODS
213      * ------------------------------------------
214      */

215
216     /**
217      * Starts the gauge statistic monitor.
218      */

219     public synchronized void start() {
220         // Reset values.
221
//
222
for (int i = 0; i < elementCount; i++) {
223             status[i] = RISING_OR_FALLING;
224             previousScanGauge[i] = null;
225         }
226         doStart();
227     }
228
229     /**
230      * Stops the gauge statistic monitor.
231      */

232     public synchronized void stop() {
233         doStop();
234     }
235
236     // GETTERS AND SETTERS
237
//--------------------
238

239     /**
240      * Gets the derived gauge of the specified object, if this object is
241      * contained in the set of observed MBeans, or <code>null</code> otherwise.
242      *
243      * @param object the name of the MBean.
244      *
245      * @return The derived gauge of the specified object.
246      *
247      * @since.unbundled JMX 1.2
248      */

249     public synchronized Number JavaDoc getDerivedGauge(ObjectName JavaDoc object) {
250         return (Number JavaDoc) super.getDerivedGauge(object);
251     }
252
253     /**
254      * Gets the derived gauge timestamp of the specified object, if
255      * this object is contained in the set of observed MBeans, or
256      * <code>null</code> otherwise.
257      *
258      * @param object the name of the object whose derived gauge
259      * timestamp is to be returned.
260      *
261      * @return The derived gauge timestamp of the specified object.
262      *
263      * @since.unbundled JMX 1.2
264      */

265     public synchronized long getDerivedGaugeTimeStamp(ObjectName JavaDoc object) {
266         return super.getDerivedGaugeTimeStamp(object);
267     }
268
269     /**
270      * Returns the derived gauge of the first object in the set of
271      * observed MBeans.
272      *
273      * @return The derived gauge.
274      *
275      * @deprecated As of JMX 1.2, replaced by
276      * {@link #getDerivedGauge(ObjectName)}
277      */

278     @Deprecated JavaDoc
279     public synchronized Number JavaDoc getDerivedGauge() {
280         return (Number JavaDoc) derivedGauge[0];
281     }
282
283     /**
284      * Gets the derived gauge timestamp of the first object in the set
285      * of observed MBeans.
286      *
287      * @return The derived gauge timestamp.
288      *
289      * @deprecated As of JMX 1.2, replaced by
290      * {@link #getDerivedGaugeTimeStamp(ObjectName)}
291      */

292     @Deprecated JavaDoc
293     public synchronized long getDerivedGaugeTimeStamp() {
294         return derivedGaugeTimestamp[0];
295     }
296
297     /**
298      * Gets the high threshold value common to all observed MBeans.
299      *
300      * @return The high threshold value.
301      *
302      * @see #setThresholds
303      */

304     public synchronized Number JavaDoc getHighThreshold() {
305         return highThreshold;
306     }
307
308     /**
309      * Gets the low threshold value common to all observed MBeans.
310      *
311      * @return The low threshold value.
312      *
313      * @see #setThresholds
314      */

315     public synchronized Number JavaDoc getLowThreshold() {
316         return lowThreshold;
317     }
318
319     /**
320      * Sets the high and the low threshold values common to all
321      * observed MBeans.
322      *
323      * @param highValue The high threshold value.
324      * @param lowValue The low threshold value.
325      *
326      * @exception IllegalArgumentException The specified high/low
327      * threshold is null or the low threshold is greater than the high
328      * threshold or the high threshold and the low threshold are not
329      * of the same type.
330      *
331      * @see #getHighThreshold
332      * @see #getLowThreshold
333      */

334     public synchronized void setThresholds(Number JavaDoc highValue, Number JavaDoc lowValue)
335             throws IllegalArgumentException JavaDoc {
336
337         if ((highValue == null) || (lowValue == null)) {
338             throw new IllegalArgumentException JavaDoc("Null threshold value");
339         }
340
341         if (highValue.getClass() != lowValue.getClass()) {
342             throw new IllegalArgumentException JavaDoc("Different type " +
343                                                "threshold values");
344         }
345
346         if (isFirstStrictlyGreaterThanLast(lowValue, highValue,
347                                            highValue.getClass().getName())) {
348             throw new IllegalArgumentException JavaDoc("High threshold less than " +
349                                                "low threshold");
350         }
351
352         highThreshold = highValue;
353         lowThreshold = lowValue;
354
355         for (int i = 0; i < elementCount; i++) {
356             resetAlreadyNotified(i, THRESHOLD_ERROR_NOTIFIED);
357
358             // Reset values.
359
//
360
status[i] = RISING_OR_FALLING;
361         }
362     }
363
364     /**
365      * Gets the high notification's on/off switch value common to all
366      * observed MBeans.
367      *
368      * @return <CODE>true</CODE> if the gauge monitor notifies when
369      * exceeding the high threshold, <CODE>false</CODE> otherwise.
370      *
371      * @see #setNotifyHigh
372      */

373     public synchronized boolean getNotifyHigh() {
374         return notifyHigh;
375     }
376
377     /**
378      * Sets the high notification's on/off switch value common to all
379      * observed MBeans.
380      *
381      * @param value The high notification's on/off switch value.
382      *
383      * @see #getNotifyHigh
384      */

385     public synchronized void setNotifyHigh(boolean value) {
386         notifyHigh = value;
387     }
388
389     /**
390      * Gets the low notification's on/off switch value common to all
391      * observed MBeans.
392      *
393      * @return <CODE>true</CODE> if the gauge monitor notifies when
394      * exceeding the low threshold, <CODE>false</CODE> otherwise.
395      *
396      * @see #setNotifyLow
397      */

398     public synchronized boolean getNotifyLow() {
399         return notifyLow;
400     }
401
402     /**
403      * Sets the low notification's on/off switch value common to all
404      * observed MBeans.
405      *
406      * @param value The low notification's on/off switch value.
407      *
408      * @see #getNotifyLow
409      */

410     public synchronized void setNotifyLow(boolean value) {
411         notifyLow = value;
412     }
413
414     /**
415      * Gets the difference mode flag value common to all observed MBeans.
416      *
417      * @return <CODE>true</CODE> if the difference mode is used,
418      * <CODE>false</CODE> otherwise.
419      *
420      * @see #setDifferenceMode
421      */

422     public synchronized boolean getDifferenceMode() {
423         return differenceMode;
424     }
425
426     /**
427      * Sets the difference mode flag value common to all observed MBeans.
428      *
429      * @param value The difference mode flag value.
430      *
431      * @see #getDifferenceMode
432      */

433     public synchronized void setDifferenceMode(boolean value) {
434         differenceMode = value;
435
436         // Reset values.
437
//
438
for (int i = 0; i < elementCount; i++) {
439             status[i] = RISING_OR_FALLING;
440             previousScanGauge[i] = null;
441         }
442     }
443
444    /**
445      * Returns a <CODE>NotificationInfo</CODE> object containing the
446      * name of the Java class of the notification and the notification
447      * types sent by the gauge monitor.
448      */

449     public MBeanNotificationInfo JavaDoc[] getNotificationInfo() {
450         return notifsInfo;
451     }
452
453     /*
454      * ------------------------------------------
455      * PRIVATE METHODS
456      * ------------------------------------------
457      */

458
459     /**
460      * Updates the derived gauge attribute of the observed object at
461      * the specified index.
462      *
463      * @param scanGauge The value of the observed attribute.
464      * @param index The index of the observed object.
465      * @return <CODE>true</CODE> if the derived gauge value is valid,
466      * <CODE>false</CODE> otherwise. The derived gauge value is
467      * invalid when the differenceMode flag is set to
468      * <CODE>true</CODE> and it is the first notification (so we
469      * haven't 2 consecutive values to update the derived gauge).
470      */

471     private synchronized boolean updateDerivedGauge(Object JavaDoc scanGauge,
472                                                     int index) {
473
474         boolean is_derived_gauge_valid;
475
476         // The gauge difference mode is used.
477
//
478
if (differenceMode) {
479
480             // The previous scan gauge has been initialized.
481
//
482
if (previousScanGauge[index] != null) {
483                 setDerivedGaugeWithDifference((Number JavaDoc)scanGauge, index);
484                 is_derived_gauge_valid = true;
485             }
486             // The previous scan gauge has not been initialized.
487
// We cannot update the derived gauge...
488
//
489
else {
490                 is_derived_gauge_valid = false;
491             }
492             previousScanGauge[index] = (Number JavaDoc)scanGauge;
493         }
494         // The gauge difference mode is not used.
495
//
496
else {
497             derivedGauge[index] = (Number JavaDoc)scanGauge;
498             is_derived_gauge_valid = true;
499         }
500
501         return is_derived_gauge_valid;
502     }
503
504     /**
505      * Updates the notification attribute of the observed object at the
506      * specified index and notifies the listeners only once if the notify flag
507      * is set to <CODE>true</CODE>.
508      * @param index The index of the observed object.
509      */

510     private StatisticMonitorNotification updateNotifications(int index) {
511
512         StatisticMonitorNotification n = null;
513
514         // Send high notification if notifyHigh is true.
515
// Send low notification if notifyLow is true.
516
//
517
synchronized(this) {
518             if (status[index] == RISING_OR_FALLING) {
519                 if (isFirstGreaterThanLast((Number JavaDoc)derivedGauge[index],
520                                            highThreshold,
521                                            type[index])) {
522                     if (notifyHigh) {
523                         n = new StatisticMonitorNotification(
524                                 THRESHOLD_HIGH_VALUE_EXCEEDED,
525                                 this,
526                                 0,
527                                 0,
528                                 "",
529                                 null,
530                                 null,
531                                 null,
532                                 highThreshold);
533                     }
534                     status[index] = FALLING;
535                 } else if (isFirstGreaterThanLast(lowThreshold,
536                                                   (Number JavaDoc)derivedGauge[index],
537                                                   type[index])) {
538                     if (notifyLow) {
539                         n = new StatisticMonitorNotification(
540                                 THRESHOLD_LOW_VALUE_EXCEEDED,
541                                 this,
542                                 0,
543                                 0,
544                                 "",
545                                 null,
546                                 null,
547                                 null,
548                                 lowThreshold);
549                     }
550                     status[index] = RISING;
551                 }
552             } else {
553                 if (status[index] == RISING) {
554                     if (isFirstGreaterThanLast((Number JavaDoc)derivedGauge[index],
555                                                highThreshold,
556                                                type[index])) {
557                         if (notifyHigh) {
558                             n = new StatisticMonitorNotification(
559                                     THRESHOLD_HIGH_VALUE_EXCEEDED,
560                                     this,
561                                     0,
562                                     0,
563                                     "",
564                                     null,
565                                     null,
566                                     null,
567                                     highThreshold);
568                         }
569                         status[index] = FALLING;
570                     }
571                 } else if (status[index] == FALLING) {
572                     if (isFirstGreaterThanLast(lowThreshold,
573                                                (Number JavaDoc)derivedGauge[index],
574                                                type[index])) {
575                         if (notifyLow) {
576                             n = new StatisticMonitorNotification(
577                                     THRESHOLD_LOW_VALUE_EXCEEDED,
578                                     this,
579                                     0,
580                                     0,
581                                     "",
582                                     null,
583                                     null,
584                                     null,
585                                     lowThreshold);
586                         }
587                         status[index] = RISING;
588                     }
589                 }
590             }
591         }
592
593         return n;
594     }
595
596     /**
597      * Sets the derived gauge when the differenceMode flag is set to
598      * <CODE>true</CODE>. Both integer and floating-point types are
599      * allowed.
600      *
601      * @param scanGauge The value of the observed attribute.
602      * @param index The index of the observed object.
603      */

604     private synchronized void setDerivedGaugeWithDifference(Number JavaDoc scanGauge,
605                                                             int index) {
606         Number JavaDoc prev = previousScanGauge[index];
607         Number JavaDoc der;
608         switch (type[index]) {
609         case INTEGER:
610             der = new Integer JavaDoc(((Integer JavaDoc)scanGauge).intValue() -
611                               ((Integer JavaDoc)prev).intValue());
612             break;
613         case BYTE:
614             der = new Byte JavaDoc((byte)(((Byte JavaDoc)scanGauge).byteValue() -
615                                   ((Byte JavaDoc)prev).byteValue()));
616             break;
617         case SHORT:
618             der = new Short JavaDoc((short)(((Short JavaDoc)scanGauge).shortValue() -
619                                     ((Short JavaDoc)prev).shortValue()));
620             break;
621         case LONG:
622             der = new Long JavaDoc(((Long JavaDoc)scanGauge).longValue() -
623                            ((Long JavaDoc)prev).longValue());
624             break;
625         case FLOAT:
626             der = new Float JavaDoc(((Float JavaDoc)scanGauge).floatValue() -
627                             ((Float JavaDoc)prev).floatValue());
628             break;
629         case DOUBLE:
630             der = new Double JavaDoc(((Double JavaDoc)scanGauge).doubleValue() -
631                              ((Double JavaDoc)prev).doubleValue());
632             break;
633         default:
634             // Should never occur...
635
if ( _logger.isLoggable(Level.WARNING) )
636                 _logger.log(Level.WARNING,"The threshold type is invalid");
637             return;
638         }
639         derivedGauge[index] = der;
640     }
641
642     /**
643      * Tests if the first specified Number is greater than or equal to
644      * the last. Both integer and floating-point types are allowed.
645      *
646      * @param greater The first Number to compare with the second.
647      * @param less The second Number to compare with the first.
648      * @param type The number type.
649      * @return <CODE>true</CODE> if the first specified Number is
650      * greater than or equal to the last, <CODE>false</CODE>
651      * otherwise.
652      */

653     private boolean isFirstGreaterThanLast(Number JavaDoc greater,
654                                            Number JavaDoc less,
655                                            NumericalType type) {
656
657         switch(type) {
658         case INTEGER:
659         case BYTE:
660         case SHORT:
661         case LONG:
662             return (greater.longValue() >= less.longValue());
663         case FLOAT:
664         case DOUBLE:
665             return (greater.doubleValue() >= less.doubleValue());
666         default:
667             // Should never occur...
668
if ( _logger.isLoggable(Level.WARNING) )
669                 _logger.log(Level.WARNING,"The threshold type is invalid");
670             return false;
671         }
672     }
673
674     /**
675      * Tests if the first specified Number is strictly greater than the last.
676      * Both integer and floating-point types are allowed.
677      *
678      * @param greater The first Number to compare with the second.
679      * @param less The second Number to compare with the first.
680      * @param className The number class name.
681      * @return <CODE>true</CODE> if the first specified Number is
682      * strictly greater than the last, <CODE>false</CODE> otherwise.
683      */

684     private boolean isFirstStrictlyGreaterThanLast(Number JavaDoc greater,
685                                                    Number JavaDoc less,
686                                                    String JavaDoc className) {
687
688         if (className.equals("java.lang.Integer") ||
689             className.equals("java.lang.Byte") ||
690             className.equals("java.lang.Short") ||
691             className.equals("java.lang.Long")) {
692
693             return (greater.longValue() > less.longValue());
694         }
695         else if (className.equals("java.lang.Float") ||
696                  className.equals("java.lang.Double")) {
697
698             return (greater.doubleValue() > less.doubleValue());
699         }
700         else {
701             // Should never occur...
702
if ( _logger.isLoggable(Level.WARNING) )
703                 _logger.log(Level.WARNING,"The threshold type is invalid");
704             return false;
705         }
706     }
707
708     /*
709      * ------------------------------------------
710      * PACKAGE METHODS
711      * ------------------------------------------
712      */

713
714     /**
715      * This method globally sets the derived gauge type for the given
716      * "object" and "attribute" after checking that the type of the
717      * supplied observed attribute value is one of the value types
718      * supported by this monitor.
719      */

720     boolean isComparableTypeValid(ObjectName JavaDoc object,
721                                   String JavaDoc attribute,
722                                   Comparable JavaDoc<?> value) {
723         int index = indexOf(object);
724
725         // Check that the observed attribute is either of type
726
// "Integer" or "Float".
727
//
728
if (value instanceof Integer JavaDoc) {
729             type[index] = INTEGER;
730         } else if (value instanceof Byte JavaDoc) {
731             type[index] = BYTE;
732         } else if (value instanceof Short JavaDoc) {
733             type[index] = SHORT;
734         } else if (value instanceof Long JavaDoc) {
735             type[index] = LONG;
736         } else if (value instanceof Float JavaDoc) {
737             type[index] = FLOAT;
738         } else if (value instanceof Double JavaDoc) {
739             type[index] = DOUBLE;
740         } else {
741             return false;
742         }
743         return true;
744     }
745
746     Comparable JavaDoc<?> getDerivedGaugeFromComparable(ObjectName JavaDoc object,
747                                                 String JavaDoc attribute,
748                                                 Comparable JavaDoc<?> value) {
749         int index = indexOf(object);
750
751         // Update the derived gauge attributes and check the
752
// validity of the new value. The derived gauge value
753
// is invalid when the differenceMode flag is set to
754
// true and it is the first notification, i.e. we
755
// haven't got 2 consecutive values to update the
756
// derived gauge.
757
//
758
derivedGaugeValid[index] = updateDerivedGauge(value, index);
759
760         return (Comparable JavaDoc<?>) derivedGauge[index];
761     }
762
763     void onErrorNotification(StatisticMonitorNotification notification) {
764         int index = indexOf(notification.getObservedObject());
765         synchronized(this) {
766             // Reset values.
767
//
768
status[index] = RISING_OR_FALLING;
769             previousScanGauge[index] = null;
770         }
771     }
772
773     StatisticMonitorNotification buildAlarmNotification(ObjectName JavaDoc object,
774                                                String JavaDoc attribute,
775                                                Comparable JavaDoc<?> value) {
776         int index = indexOf(object);
777         
778         // Notify the listeners if the updated derived
779
// gauge value is valid.
780
//
781
StatisticMonitorNotification alarm = null;
782         if (derivedGaugeValid[index])
783             alarm = updateNotifications(index);
784         return alarm;
785     }
786
787     /**
788      * Tests if the threshold high and threshold low are both of the
789      * same type as the gauge. Both integer and floating-point types
790      * are allowed.
791      *
792      * Note:
793      * If the optional lowThreshold or highThreshold have not been
794      * initialized, their default value is an Integer object with
795      * a value equal to zero.
796      *
797      * @param object The observed object.
798      * @param attribute The observed attribute.
799      * @param value The sample value.
800      * @return <CODE>true</CODE> if type is the same,
801      * <CODE>false</CODE> otherwise.
802      */

803     synchronized boolean isThresholdTypeValid(ObjectName JavaDoc object,
804                                               String JavaDoc attribute,
805                                               Comparable JavaDoc<?> value) {
806         int index = indexOf(object);
807         Class JavaDoc<? extends Number JavaDoc> c = classForType(type[index]);
808         return (isValidForType(highThreshold, c) &&
809                 isValidForType(lowThreshold, c));
810     }
811
812     /**
813      * This method is called when adding a new observed object in the vector.
814      * It updates all the gauge specific arrays.
815      * @param index The index of the observed object.
816      */

817     synchronized void insertSpecificElementAt(int index) {
818         // Update previousScanGauge, status, type and derivedGaugeValid arrays.
819
//
820
if (elementCount >= previousScanGauge.length) {
821             previousScanGauge = expandArray(previousScanGauge);
822             status = expandArray(status);
823             type = expandArray(type);
824             derivedGaugeValid = expandArray(derivedGaugeValid);
825         }
826         previousScanGauge[index] = null;
827         status[index] = RISING_OR_FALLING;
828         type[index] = INTEGER;
829         derivedGaugeValid[index] = false;
830     }
831
832     /**
833      * This method is called when removing an observed object from the vector.
834      * It updates all the gauge specific arrays.
835      * @param index The index of the observed object.
836      */

837     synchronized void removeSpecificElementAt(int index) {
838         // Update previousScanGauge, status, type and derivedGaugeValid arrays.
839
//
840
removeElementAt(previousScanGauge, index);
841         removeElementAt(status, index);
842         removeElementAt(type, index);
843         removeElementAt(derivedGaugeValid, index);
844     }
845 }
846
Popular Tags