1 22 package org.jboss.monitor; 23 24 import org.jboss.system.ServiceMBeanSupport; 25 import org.jboss.logging.Logger; 26 27 import javax.management.ObjectName ; 28 import javax.management.MBeanException ; 29 import javax.management.AttributeNotFoundException ; 30 import javax.management.InstanceNotFoundException ; 31 import javax.management.ReflectionException ; 32 33 40 public class StringThresholdMonitor extends JBossMonitor implements StringThresholdMonitorMBean 41 { 42 protected String thresholdString; 43 protected boolean equalityTriggersAlert; 44 45 protected void testThreshold() 46 { 47 if (alertSent) return; 48 String value = null; 49 try 50 { 51 value = (String )getServer().getAttribute(observedObject, attribute); 52 if (equalityTriggersAlert) { 54 if (!thresholdString.equals(value)) 55 { 56 return; 57 } 58 } 59 else { 61 if (thresholdString.equals(value)) 62 { 63 return; 64 } 65 } 66 } 67 catch (Exception e) 68 { 69 throw new RuntimeException ("Failed to compare threshold, mbean failure"); 70 } 71 72 alertSent = true; 73 triggerTime = System.currentTimeMillis(); 74 triggeredAttributeValue = value; 75 76 StringThresholdNotification notification = new StringThresholdNotification(monitorName, getServiceName(), observedObject, 77 attribute, value, thresholdString, equalityTriggersAlert, 78 getNextNotificationSequenceNumber()); 79 this.sendNotification(notification); 80 } 81 82 public String getThreshold() 83 { 84 return thresholdString; 85 } 86 87 public void setThreshold(String val) 88 { 89 thresholdString = val; 90 } 91 92 public boolean getEqualityTriggersAlert() 93 { 94 return equalityTriggersAlert; 95 } 96 97 public void setEqualityTriggersAlert(boolean compareEqual) 98 { 99 this.equalityTriggersAlert = compareEqual; 100 } 101 } 102 | Popular Tags |