001: /**
002: * The XMOJO Project 5
003: * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005: * NO WARRANTY
006:
007: * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008: * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009: * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010: * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011: * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013: * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014: * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015: * REPAIR OR CORRECTION.
016:
017: * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018: * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019: * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020: * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021: * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022: * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023: * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024: * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025: * SUCH DAMAGES.
026: **/package javax.management.monitor;
027:
028: import javax.management.ObjectName;
029: import javax.management.MBeanServer;
030: import javax.management.Notification;
031: import javax.management.MBeanNotificationInfo;
032: import javax.management.MBeanException;
033: import javax.management.AttributeNotFoundException;
034: import javax.management.InstanceNotFoundException;
035: import javax.management.ReflectionException;
036:
037: import com.adventnet.agent.logging.Log;
038: import com.adventnet.agent.logging.LogFactory;
039:
040: /**
041: * This class defines a monitor MBean designed to observe the values of a
042: * counter attribute. Counter attributes are those types whose value is always
043: * positive or null and they can only be incremented. The counter monitor is
044: * used to observe values of attribute whose type should be of integer i.e.
045: * (<CODE>Byte</CODE>, <CODE>Integer</CODE>, <CODE>Short</CODE>, <CODE>Long</CODE>).
046: * <P>
047: * A counter monitor sends a {@link MonitorNotification#THRESHOLD_VALUE_EXCEEDED
048: * threshold notification} when the value of the counter reaches or exceeds a
049: * threshold known as the comparison level.
050: * The notify flag must be set to <CODE>true</CODE>.
051: * <BR>In addition, an offset mechanism enables particular counting intervals
052: * to be detected.
053: * <P>
054: * If the offset value is not zero, whenever the threshold is triggered by the
055: * counter value reaching a comparison level, that comparison level is
056: * incremented by the offset value. This is regarded as taking place
057: * instantaneously, that is before the count is incremented. Thus, for each
058: * level, the threshold triggers an event notification every time the count
059: * increases by an interval equal to the offset value.
060: * <P>
061: * If the counter can wrap around its maximum value, the modulus needs to be
062: * specified. The modulus is the value at which the counter is reset to zero.
063: * <P>
064: * If the counter difference mode is used, the value of the derived gauge is
065: * calculated as the difference between the observed counter values for two
066: * successive observations. If this difference is negative, the value of the
067: * derived gauge is incremented by the value of the modulus.
068: * <BR>The derived gauge value (V[t]) is calculated using the following method:
069: * <UL>
070: * <LI>if (counter[t] - counter[t-GP]) is positive then V[t] = counter[t] - counter[t-GP]
071: * <LI>if (counter[t] - counter[t-GP]) is negative then V[t] = counter[t] - counter[t-GP] + MODULUS
072: * </UL>
073: */
074: public class CounterMonitor extends Monitor implements
075: CounterMonitorMBean {
076: /**
077: * Derived gauge.
078: */
079: private Number derivedGauge = null;
080:
081: /**
082: * Counter offset.
083: * <BR>The default value is a null Integer object.
084: */
085: private Number offset = null;
086:
087: /**
088: * Counter threshold.
089: * <BR>The default value is a null Integer object.
090: */
091: private Number threshold = null;
092:
093: /**
094: * Flag indicating if the counter difference mode is used. If the counter
095: * difference mode is used, the derived gauge is the difference between
096: * two consecutive observed values. Otherwise, the derived gauge is
097: * directly the value of the observed attribute.
098: * <BR>The default value is set to <CODE>false</CODE>.
099: */
100: private boolean differenceMode = false;
101:
102: /**
103: * Flag indicating if the counter monitor notifies when exceeding the threshold.
104: * <BR>The default value is set to <CODE>true</CODE>.
105: */
106: private boolean notifyFlag = true;
107:
108: /**
109: * Counter modulus.
110: * <BR>The default value is a null Integer object.
111: */
112: private Number modulus = null;
113:
114: /**
115: * Previous derived gauge value.
116: */
117: private Number prevDerivedGauge = null;
118:
119: private Thread counterThread = null;
120: private Comparable comparableDerivedGauge = null;
121: private Notification notif = null;
122: private Number thresholdCopy = null;
123: private Comparable comparableThreshold = null;
124: private Comparable comparableThresholdExt = null;
125: private long sequenceNumber = 1;
126: private long startDate = 0;
127: private ObjectName objName = null;
128: private boolean prev_notified = false;
129: private Log log;
130:
131: /**
132: * Default Constructor.
133: */
134: public CounterMonitor() {
135: createLogger();
136: }
137:
138: /**
139: * This method gets the value of the derived gauge. The derived gauge is
140: * either the exact value of the observed attribute , or the difference
141: * between the two consecutive observed values of the attribute.
142: *
143: * @return An instance of java.lang.Number giving the value of the derived gauge.
144: */
145: public java.lang.Number getDerivedGauge() {
146: return derivedGauge;
147: }
148:
149: /**
150: * This method gets the value of the derived gauge time stamp.The derived
151: * gauge time stamp is the value(in the nearest miliseconds) when the
152: * notification was triggered.
153: *
154: * @return long value representing the time the notification was triggered.
155: */
156: public long getDerivedGaugeTimeStamp() {
157: return derivedGaugeTimeStamp;
158: }
159:
160: /**
161: * This method gets the value of the difference mode. If the difference mode
162: * is true, the difference mode option is set to calculate the value of
163: * the derived gauge.
164: *
165: * @return boolean value indicating whether the difference mode option is set.
166: */
167: public boolean getDifferenceMode() {
168: return differenceMode;
169: }
170:
171: /**
172: * This method sets the state of the difference mode.
173: *
174: * @param value boolean value representing the state of the difference mode.
175: */
176: public void setDifferenceMode(boolean value) {
177: this .differenceMode = value;
178: }
179:
180: /**
181: * This method gets the modulus value of monitor. Modulus is the value at
182: * which the counter is reset to zero.
183: *
184: * @return An instance of java.lang.Number giving the modulus value.
185: */
186: public java.lang.Number getModulus() {
187: return modulus;
188: }
189:
190: /**
191: * This method sets the modulus value of the monitor. Modulus is the value
192: * at which the counter is reset to zero.
193: *
194: * @param value An instance of java.lang.Number representing the modulus
195: * value for the derived gauge .
196: * @exception java.lang.IllegalArgumentException - The specified modulus is
197: * null or the modulus value is less than zero.
198: */
199: public void setModulus(java.lang.Number value)
200: throws IllegalArgumentException {
201: if (value == null || isLessThanZero(value))
202: throw new IllegalArgumentException(
203: "Modulus cannot be null or less than Zero");
204:
205: this .modulus = value;
206: }
207:
208: /**
209: * This method gets the notification's on/off switch value.
210: *
211: * @return a boolean value indicating the state of notification's On/Off switch.
212: */
213: public boolean getNotify() {
214: return notifyFlag;
215: }
216:
217: /**
218: * This method sets the notification's on/off switch value.
219: *
220: * @param value boolean value to set the sate of the notifications On/Off Switch.
221: */
222: public void setNotify(boolean value) {
223: this .notifyFlag = value;
224: }
225:
226: /**
227: * This method gets the offset value. Offset enables particular counting
228: * intervals to be detected.
229: *
230: * @return An instance of java.lang.Number giving the value of the offset.
231: */
232: public Number getOffset() {
233: return offset;
234: }
235:
236: /**
237: * This method sets the value of the offset.
238: *
239: * @param value An instance of java.lang.Number giving the value offset.
240: *
241: * @exception java.lang,IllegalArgumentException - The specified offset is
242: * null or the offset value is less than zero.
243: */
244: public void setOffset(java.lang.Number value)
245: throws IllegalArgumentException {
246: if (value == null || isLessThanZero(value))
247: throw new IllegalArgumentException(
248: "Offset cannot be null or less than Zero");
249:
250: this .offset = value;
251: }
252:
253: /**
254: * This method gets the value of the threshold. Threshold is the maximum
255: * value of that the attribute can reach. If the attribute reaches this
256: * comparison level or is greater than this level , notification is triggered.
257: *
258: * @return An instance of java.lang.Number giving the value of the threshold.
259: */
260: public java.lang.Number getThreshold() {
261: return threshold;
262: }
263:
264: /**
265: * This method sets the value of the threshold.Threshold is the maximum
266: * value of that the attribute can reach. If the attribute reaches this
267: * comparison level or is greater than this level , notification is triggered.
268: *
269: * @param value An instance of java.lang.Number which is the value of the threshold.
270: */
271: public void setThreshold(java.lang.Number value)
272: throws IllegalArgumentException {
273: if (value == null || isLessThanZero(value))
274: throw new IllegalArgumentException(
275: "Threshold cannot be null or zero");
276:
277: this .threshold = value;
278: thresholdCopy = value;
279: comparableThreshold = getComparableValue(value);
280: comparableThresholdExt = comparableThreshold;
281: }
282:
283: /**
284: * This method starts the counter monitor.
285: */
286: public void start() {
287: counterThread = new Thread(new CounterThread(this ));
288: isActive = true;
289: counterThread.setName("CounterMonitorThread-"
290: + counterThread.getName());
291: startDate = System.currentTimeMillis();
292: counterThread.start();
293: log.trace("CounterMonitor Started");
294: }
295:
296: /**
297: * This method stops the counter monitor.
298: */
299: public void stop() {
300: isActive = false;
301: counterThread.stop();
302: log.trace("CounterMonitor Stopped");
303: }
304:
305: /**
306: * Overriding the preRegister() of MBeanRegistration interface to store the
307: * ObjectName locally.
308: */
309: public ObjectName preRegister(MBeanServer server, ObjectName name)
310: throws Exception {
311: this .objName = name;
312: super .preRegister(server, name);
313: return name;
314: }
315:
316: /**
317: * This method allows the monitor MBean to perform any operations it needs
318: * before being de-registered by the MBean server.
319: * Stops the monitor.
320: */
321: public void preDeregister() throws Exception {
322: }
323:
324: /**
325: * This method allows the monitor MBean to perform any operations needed
326: * after having been registered in the MBean server or after the
327: * registration has failed.
328: *
329: * Not used in this context.
330: *
331: * @param registrationDone If registration is done it is true otherwise false
332: */
333: public void postRegister(Boolean registrationDone) {
334: }
335:
336: /**
337: * This method allows the monitor MBean to perform any operations needed
338: * after having been de-registered by the MBean server.
339: * Not used in this context.
340: */
341: public void postDeregister() {
342: }
343:
344: /**
345: * This method returns a NotificationInfo object containing the name of
346: * the Java class of the notification and the notification types sent by
347: * the counter monitor.
348: *
349: * @return An Array of MBeanNotificationInfo objects.
350: */
351: public MBeanNotificationInfo[] getNotificationInfo() {
352: MBeanNotificationInfo[] notifInfo = super .getNotificationInfo();
353:
354: MBeanNotificationInfo[] newNotifInfo = new MBeanNotificationInfo[notifInfo.length + 2];
355:
356: for (int i = 0; i < notifInfo.length; i++) {
357: newNotifInfo[i] = notifInfo[i];
358: }
359:
360: String[] types = { "jmx.monitor.error.threshold" };
361: newNotifInfo[newNotifInfo.length - 2] = new MBeanNotificationInfo(
362: types, "Monitor Threshold Error Notification",
363: "Emimitted for a error case in Threshold");
364:
365: String[] types1 = { "jmx.monitor.counter.threshold" };
366: newNotifInfo[newNotifInfo.length - 1] = new MBeanNotificationInfo(
367: types1, "Monitor Threshold CrossOver Notification",
368: "Emimitted for a CrossOver in monitored attribute");
369:
370: return newNotifInfo;
371: }
372:
373: //----------------------------- Private methods -------------------------//
374:
375: // This is a private method that determines if the observed Attribute is of a counter
376: // type .(i.e) byte, short , int, long. returns true if the attribute is of counter
377: // monitor type else returns false.
378: private boolean isCounterDataType(Object object) {
379: String type = object.getClass().getName();
380:
381: if (type.equals("java.lang.Byte"))
382: return true;
383: else if (type.equals("java.lang.Integer"))
384: return true;
385: else if (type.equals("java.lang.Short"))
386: return true;
387: else if (type.equals("java.lang.Long"))
388: return true;
389: else
390: return false;
391: }
392:
393: // This is a private method that takes a instance of java.lang.Number and
394: // returns a instance of Comparable with which the Number can be played
395: // with. Only CounterMonitor type has been considered.
396: private Comparable getComparableValue(Object object) {
397: Comparable toRet = null;
398: String type = object.getClass().getName();
399:
400: if (type.equals("java.lang.Byte"))
401: toRet = (Byte) object;
402: else if (type.equals("java.lang.Integer"))
403: toRet = (Integer) object;
404: else if (type.equals("java.lang.Short"))
405: toRet = (Short) object;
406: else if (type.equals("java.lang.Long"))
407: toRet = (Long) object;
408:
409: return toRet;
410: }
411:
412: private boolean isLessThanZero(Object object) {
413: String type = object.getClass().getName();
414:
415: if (type.equals("java.lang.Byte")) {
416: if (((Byte) object).byteValue() < 0)
417: return true;
418: } else if (type.equals("java.lang.Integer")) {
419: if (((Integer) object).intValue() < 0)
420: return true;
421: } else if (type.equals("java.lang.Short")) {
422: if (((Short) object).shortValue() < 0)
423: return true;
424: } else if (type.equals("java.lang.Long")) {
425: if (((Long) object).longValue() < 0)
426: return true;
427: }
428:
429: return false;
430: }
431:
432: // This is a private method that calculates the value of the derived gauge
433: // in case the difference mode is set. Derived gauge is the difference between two
434: // consecutive observed values. This returns an instance of Comparable so that
435: // it can be compared with the Threshold values.(also converted to a Comparable).
436: private Comparable calculateDerivedGauge(Object derived,
437: Object prevDerived) {
438: Comparable toRet = null;
439: String type = derived.getClass().getName();
440:
441: if (type.equals("java.lang.Byte")) {
442: /*
443: if((startDate+2*granularityPeriod) < System.currentTimeMillis())
444: return new Byte((byte)0);
445: */
446: byte b = (byte) ((((Byte) derived).byteValue()) - (((Byte) prevDerived)
447: .byteValue()));
448:
449: if (b < 0) {
450: if (modulus != null) {
451: b = (byte) (b + ((Byte) getComparableValue(modulus))
452: .byteValue());
453: } else {
454: b = 0;
455: }
456: }
457:
458: toRet = new Byte(b);
459: } else if (type.equals("java.lang.Integer")) {
460: /*
461: if((startDate+2*granularityPeriod) < System.currentTimeMillis())
462: return new Integer(0);
463: */
464: int i = (((Integer) derived).intValue())
465: - (((Integer) prevDerived).intValue());
466: if (i < 0) {
467: if (modulus != null) {
468: i = i
469: + ((Integer) getComparableValue(modulus))
470: .intValue();
471: } else {
472: i = 0;
473: }
474: }
475:
476: toRet = new Integer(i);
477: } else if (type.equals("java.lang.Short")) {
478: /*
479: if((startDate+2*granularityPeriod) < System.currentTimeMillis())
480: return new Short((short)0);
481: */
482: short s = (short) ((((Short) derived).shortValue()) - (((Short) prevDerived)
483: .shortValue()));
484: if (s < 0) {
485: if (modulus != null) {
486: s = (short) (s + ((Short) getComparableValue(modulus))
487: .shortValue());
488: } else {
489: s = 0;
490: }
491: }
492: toRet = new Short(s);
493: } else if (type.equals("java.lang.Long")) {
494: /*
495: if((startDate+2*granularityPeriod) < System.currentTimeMillis())
496: return new Long(0);
497: */
498: long l = (((Long) derived).longValue())
499: - (((Long) prevDerived).longValue());
500: if (l < 0) {
501: if (modulus != null) {
502: l = l
503: + ((Long) getComparableValue(modulus))
504: .longValue();
505: } else {
506: l = 0;
507: }
508: }
509: toRet = new Long(l);
510: }
511:
512: return toRet;
513: }
514:
515: // This is a private method that adds the value of the threshold and offset,
516: // in case offset is set.
517: private Comparable addThresholdAndOffset(Object threshold,
518: Object offset) {
519: Comparable toRet = null;
520: String type = threshold.getClass().getName();
521:
522: if (type.equals("java.lang.Byte")) {
523: toRet = new Byte(
524: (byte) ((((Byte) threshold).byteValue()) + (((Byte) offset)
525: .byteValue())));
526: } else if (type.equals("java.lang.Integer")) {
527: toRet = new Integer((((Integer) threshold).intValue())
528: + (((Integer) offset).intValue()));
529: } else if (type.equals("java.lang.Short")) {
530: toRet = new Short((short) ((((Short) threshold)
531: .shortValue()) + (((Short) offset).shortValue())));
532: } else if (type.equals("java.lang.Long")) {
533: toRet = new Long((((Long) threshold).longValue())
534: + (((Long) offset).longValue()));
535: }
536:
537: return toRet;
538: }
539:
540: private void checkForRollOver(Number derivedGauge) {
541: //To be done
542: }
543:
544: private void createLogger() {
545: try {
546: log = LogFactory.getInstance("JMX");
547: } catch (Exception e) {
548: e.printStackTrace();
549: }
550: }
551:
552: //------------------------------ Inner class ----------------------------//
553:
554: // This is an inner class that implements runnable and runs in a separate
555: // thread when the counter is started. It polls the value of the observed
556: // attribute for the time specified by the granularity period.
557: class CounterThread implements Runnable {
558: Object obj = null;
559: Number prevDerivedGauge = null;
560: Number storedDerivedGauge = null;
561: CounterMonitor monitor = null;
562: boolean isRollOver = false;
563:
564: CounterThread(CounterMonitor monitor) {
565: this .monitor = monitor;
566: }
567:
568: public void run() {
569: while (true) {
570: try {
571: obj = server.getAttribute(observedObject,
572: attributeName);
573: derivedGaugeTimeStamp = System.currentTimeMillis();
574: } catch (InstanceNotFoundException ine) {
575: if (Monitor.OBSERVED_OBJECT_ERROR_NOTIFIED == 1) {
576: sendNotification(new MonitorNotification(
577: MonitorNotification.OBSERVED_OBJECT_ERROR,
578: monitor, observedObject, attributeName,
579: null, null, sequenceNumber++));
580: Monitor.OBSERVED_OBJECT_ERROR_NOTIFIED = 0;
581: }
582: sleep();
583: continue;
584: } catch (AttributeNotFoundException ane) {
585: if (Monitor.OBSERVED_ATTRIBUTE_ERROR_NOTIFIED == 1) {
586: sendNotification(new MonitorNotification(
587: MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
588: monitor, observedObject, attributeName,
589: null, null, sequenceNumber++));
590: Monitor.OBSERVED_ATTRIBUTE_ERROR_NOTIFIED = 0;
591: }
592: sleep();
593: continue;
594: } catch (MBeanException mbe) {
595: if (Monitor.RUNTIME_ERROR_NOTIFIED == 1) {
596: sendNotification(new MonitorNotification(
597: MonitorNotification.RUNTIME_ERROR,
598: monitor, observedObject, attributeName,
599: null, null, sequenceNumber++));
600: Monitor.RUNTIME_ERROR_NOTIFIED = 0;
601: }
602: sleep();
603: continue;
604: } catch (ReflectionException re) {
605: if (Monitor.RUNTIME_ERROR_NOTIFIED == 1) {
606: sendNotification(new MonitorNotification(
607: MonitorNotification.RUNTIME_ERROR,
608: monitor, observedObject, attributeName,
609: null, null, sequenceNumber++));
610: Monitor.RUNTIME_ERROR_NOTIFIED = 0;
611: }
612: sleep();
613: continue;
614: } catch (Exception e) {
615: if (Monitor.RUNTIME_ERROR_NOTIFIED == 1) {
616: sendNotification(new MonitorNotification(
617: MonitorNotification.RUNTIME_ERROR,
618: monitor, observedObject, attributeName,
619: null, null, sequenceNumber++));
620: Monitor.RUNTIME_ERROR_NOTIFIED = 0;
621: }
622: sleep();
623: continue;
624: }
625:
626: // The following if loop checks if the observedAttribute type
627: // is that of a counterMonitor Type. If it is not, sends a
628: // notification and throws a monitorsettingexception.
629: if (obj == null) {
630: continue;
631: }
632:
633: if (!isCounterDataType(obj)) {
634: sendNotification(new MonitorNotification(
635: MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
636: monitor, observedObject, attributeName,
637: null, null, sequenceNumber++));
638: //throw new MonitorSettingException();
639: } else {
640: derivedGauge = (Number) obj;
641: comparableDerivedGauge = getComparableValue(derivedGauge);
642:
643: if (isRollOver) {
644: if (getComparableValue(storedDerivedGauge)
645: .compareTo(comparableDerivedGauge) > 0) {
646: comparableThresholdExt = getComparableValue(threshold);
647: //derivedGauge = new Integer(0);
648: isRollOver = false;
649: }
650: }
651:
652: if (differenceMode) {
653: if (prevDerivedGauge == null) {
654: prevDerivedGauge = derivedGauge;
655: }
656:
657: if (derivedGauge.longValue() < prevDerivedGauge
658: .longValue()) {
659: comparableThresholdExt = getComparableValue(threshold);
660: }
661:
662: derivedGauge = (Number) (calculateDerivedGauge(
663: derivedGauge, prevDerivedGauge));
664:
665: comparableDerivedGauge = getComparableValue(derivedGauge);
666: checkForRollOver(derivedGauge);
667: }
668:
669: if (comparableDerivedGauge
670: .compareTo(comparableThresholdExt) >= 0) {
671: notif = new MonitorNotification(
672: MonitorNotification.THRESHOLD_VALUE_EXCEEDED,
673: monitor, observedObject, attributeName,
674: derivedGauge, threshold,
675: sequenceNumber++);
676:
677: if (notifyFlag && !prev_notified) {
678: sendNotification(notif);
679: prev_notified = true;
680: }
681:
682: if (offset != null) {
683: if (!(offset.getClass().getName()
684: .equals(obj.getClass().getName()))) {
685: sendNotification(new MonitorNotification(
686: MonitorNotification.THRESHOLD_ERROR,
687: monitor, observedObject,
688: attributeName, null, null,
689: sequenceNumber++));
690: throw new MonitorSettingException();
691: }
692:
693: if (offset.intValue() > 0) {
694: while (comparableThresholdExt
695: .compareTo(comparableDerivedGauge) <= 0) {
696: comparableThresholdExt = addThresholdAndOffset(
697: comparableThresholdExt,
698: offset);
699: }
700: }
701: }
702:
703: if (modulus != null && modulus.intValue() > 0) {
704: if (!(offset.getClass().getName()
705: .equals(obj.getClass().getName()))) {
706: sendNotification(new MonitorNotification(
707: MonitorNotification.THRESHOLD_ERROR,
708: monitor, observedObject,
709: attributeName, null, null,
710: sequenceNumber++));
711: throw new MonitorSettingException();
712: }
713:
714: Comparable comparableModulus = getComparableValue(modulus);
715:
716: if (modulus instanceof Byte) {
717: }
718:
719: try {
720: if (comparableThresholdExt
721: .compareTo(comparableModulus) > 0) {
722: //derivedGauge = new Integer(0);
723: isRollOver = true;
724: storedDerivedGauge = derivedGauge;
725: //comparableThresholdExt = getComparableValue(threshold);
726: }
727: } catch (ClassCastException cce) {
728: //do nothing
729: //Should I throw a MonitorSettingException();
730: }
731: }
732: } else {
733: prev_notified = false;
734: }
735:
736: try {
737: prevDerivedGauge = (Number) obj;
738: Thread.sleep(granularityPeriod);
739: } catch (InterruptedException ie) {
740: //ie.printStackTrace();
741: }
742: }
743: }
744: }
745:
746: private void sleep() {
747: try {
748: Thread.sleep(granularityPeriod);
749: } catch (Exception e) {
750: }
751: }
752:
753: }//End the CounterMonitor Thread class.
754:
755: }//End the CounterMonitor class.
|