001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.monitor.alarm;
023:
024: import java.util.HashMap;
025: import java.util.Map;
026:
027: /**
028: * Misc utilities
029: *
030: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
031: * @version $Revision: 57210 $
032: */
033: public class AlarmHelper implements Alarm {
034: // Constructors --------------------------------------------------
035:
036: /**
037: * Do not allow object creation
038: */
039: private AlarmHelper() {
040: // empty
041: }
042:
043: // Static --------------------------------------------------------
044:
045: /**
046: * Return the severity in String form
047: */
048: public static String getSeverityAsString(int severity) {
049: if (severity < SEVERITY_NORMAL || severity > SEVERITY_UNKNOWN) {
050: severity = SEVERITY_UNKNOWN;
051: }
052: return SEVERITY_STRINGS[severity];
053: }
054:
055: /**
056: * Return the alarm state in String form
057: */
058: public static String getStateAsString(int alarmState) {
059: if (alarmState < STATE_CLEARED || alarmState > STATE_NONE) {
060: alarmState = STATE_NONE;
061: }
062: return STATE_STRINGS[alarmState];
063: }
064:
065: public static Map getAlarmTableNotificationStats(
066: AlarmTableNotification[] almtab) {
067: // counters
068: int stateCleared = 0;
069: int stateChanged = 0;
070: int stateCreated = 0;
071: int stateNone = 0;
072:
073: int severityNormal = 0;
074: int severityWarning = 0;
075: int severityMinor = 0;
076: int severityMajor = 0;
077: int severityCritical = 0;
078: int severityUnknown = 0;
079:
080: if (almtab != null) {
081: for (int i = 0; i < almtab.length; i++) {
082: AlarmTableNotification atn = almtab[i];
083: switch (atn.getAlarmState()) {
084: case STATE_CLEARED:
085: ++stateCleared;
086: break;
087: case STATE_CHANGED:
088: ++stateChanged;
089: break;
090: case STATE_CREATED:
091: ++stateCreated;
092: break;
093: case STATE_NONE:
094: default:
095: ++stateNone;
096: break;
097: }
098: switch (atn.getSeverity()) {
099: case SEVERITY_NORMAL:
100: ++severityNormal;
101: break;
102: case SEVERITY_WARNING:
103: ++severityWarning;
104: break;
105: case SEVERITY_MINOR:
106: ++severityMinor;
107: break;
108: case SEVERITY_MAJOR:
109: ++severityMajor;
110: break;
111: case SEVERITY_CRITICAL:
112: ++severityCritical;
113: break;
114: case SEVERITY_UNKNOWN:
115: default:
116: ++severityUnknown;
117: break;
118: }
119: }
120: Map stats = new HashMap();
121:
122: stats.put(getSeverityAsString(SEVERITY_NORMAL),
123: new Integer(severityNormal));
124: stats.put(getSeverityAsString(SEVERITY_WARNING),
125: new Integer(severityWarning));
126: stats.put(getSeverityAsString(SEVERITY_MINOR), new Integer(
127: severityMinor));
128: stats.put(getSeverityAsString(SEVERITY_MAJOR), new Integer(
129: severityMajor));
130: stats.put(getSeverityAsString(SEVERITY_CRITICAL),
131: new Integer(severityCritical));
132: stats.put(getSeverityAsString(SEVERITY_UNKNOWN),
133: new Integer(severityUnknown));
134:
135: stats.put(getStateAsString(STATE_CLEARED), new Integer(
136: stateCleared));
137: stats.put(getStateAsString(STATE_CHANGED), new Integer(
138: stateChanged));
139: stats.put(getStateAsString(STATE_CREATED), new Integer(
140: stateCreated));
141: stats.put(getStateAsString(STATE_NONE), new Integer(
142: stateNone));
143:
144: return stats;
145: } else {
146: return null;
147: }
148: }
149: }
|