01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: /**
34: * Comment
35: *
36: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
37: * @version $Revision: 57210 $
38: *
39: **/
40: public class StringThresholdMonitor extends JBossMonitor implements
41: StringThresholdMonitorMBean {
42: protected String thresholdString;
43: protected boolean equalityTriggersAlert;
44:
45: protected void testThreshold() {
46: if (alertSent)
47: return;
48: String value = null;
49: try {
50: value = (String) getServer().getAttribute(observedObject,
51: attribute);
52: if (equalityTriggersAlert) // alert trigger when value == threshold
53: {
54: if (!thresholdString.equals(value)) {
55: return;
56: }
57: } else // alert triggered when value != threshold
58: {
59: if (thresholdString.equals(value)) {
60: return;
61: }
62: }
63: } catch (Exception e) {
64: throw new RuntimeException(
65: "Failed to compare threshold, mbean failure");
66: }
67:
68: alertSent = true;
69: triggerTime = System.currentTimeMillis();
70: triggeredAttributeValue = value;
71:
72: StringThresholdNotification notification = new StringThresholdNotification(
73: monitorName, getServiceName(), observedObject,
74: attribute, value, thresholdString,
75: equalityTriggersAlert,
76: getNextNotificationSequenceNumber());
77: this .sendNotification(notification);
78: }
79:
80: public String getThreshold() {
81: return thresholdString;
82: }
83:
84: public void setThreshold(String val) {
85: thresholdString = val;
86: }
87:
88: public boolean getEqualityTriggersAlert() {
89: return equalityTriggersAlert;
90: }
91:
92: public void setEqualityTriggersAlert(boolean compareEqual) {
93: this.equalityTriggersAlert = compareEqual;
94: }
95: }
|