KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > monitor > alarm > AlarmHelper


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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.alarm;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 /**
28  * Misc utilities
29  *
30  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
31  * @version $Revision: 37459 $
32  */

33 public class AlarmHelper implements Alarm
34 {
35    // Constructors --------------------------------------------------
36

37    /**
38     * Do not allow object creation
39     */

40    private AlarmHelper()
41    {
42       // empty
43
}
44
45    // Static --------------------------------------------------------
46

47    /**
48     * Return the severity in String form
49     */

50    public static String JavaDoc getSeverityAsString(int severity)
51    {
52       if (severity < SEVERITY_NORMAL || severity > SEVERITY_UNKNOWN)
53       {
54          severity = SEVERITY_UNKNOWN;
55       }
56       return SEVERITY_STRINGS[severity];
57    }
58    
59    /**
60     * Return the alarm state in String form
61     */

62    public static String JavaDoc getStateAsString(int alarmState)
63    {
64       if (alarmState < STATE_CLEARED || alarmState > STATE_NONE)
65       {
66          alarmState = STATE_NONE;
67       }
68       return STATE_STRINGS[alarmState];
69    }
70    
71    public static Map JavaDoc getAlarmTableNotificationStats(AlarmTableNotification[] almtab)
72    {
73       // counters
74
int stateCleared = 0;
75       int stateChanged = 0;
76       int stateCreated = 0;
77       int stateNone = 0;
78       
79       int severityNormal = 0;
80       int severityWarning = 0;
81       int severityMinor = 0;
82       int severityMajor = 0;
83       int severityCritical = 0;
84       int severityUnknown = 0;
85       
86       if (almtab != null)
87       {
88          for (int i = 0; i < almtab.length; i++)
89          {
90             AlarmTableNotification atn = almtab[i];
91             switch (atn.getAlarmState())
92             {
93                case STATE_CLEARED:
94                   ++stateCleared;
95                   break;
96                case STATE_CHANGED:
97                   ++stateChanged;
98                   break;
99                case STATE_CREATED:
100                   ++stateCreated;
101                   break;
102                case STATE_NONE:
103                default:
104                   ++stateNone;
105                   break;
106             }
107             switch (atn.getSeverity())
108             {
109                case SEVERITY_NORMAL:
110                   ++severityNormal;
111                   break;
112                case SEVERITY_WARNING:
113                   ++severityWarning;
114                   break;
115                case SEVERITY_MINOR:
116                   ++severityMinor;
117                   break;
118                case SEVERITY_MAJOR:
119                   ++severityMajor;
120                   break;
121                case SEVERITY_CRITICAL:
122                   ++severityCritical;
123                   break;
124                case SEVERITY_UNKNOWN:
125                default:
126                   ++severityUnknown;
127                   break;
128             }
129          }
130          Map JavaDoc stats = new HashMap JavaDoc();
131          
132          stats.put(getSeverityAsString(SEVERITY_NORMAL), new Integer JavaDoc(severityNormal));
133          stats.put(getSeverityAsString(SEVERITY_WARNING), new Integer JavaDoc(severityWarning));
134          stats.put(getSeverityAsString(SEVERITY_MINOR), new Integer JavaDoc(severityMinor));
135          stats.put(getSeverityAsString(SEVERITY_MAJOR), new Integer JavaDoc(severityMajor));
136          stats.put(getSeverityAsString(SEVERITY_CRITICAL), new Integer JavaDoc(severityCritical));
137          stats.put(getSeverityAsString(SEVERITY_UNKNOWN), new Integer JavaDoc(severityUnknown));
138          
139          stats.put(getStateAsString(STATE_CLEARED), new Integer JavaDoc(stateCleared));
140          stats.put(getStateAsString(STATE_CHANGED), new Integer JavaDoc(stateChanged));
141          stats.put(getStateAsString(STATE_CREATED), new Integer JavaDoc(stateCreated));
142          stats.put(getStateAsString(STATE_NONE), new Integer JavaDoc(stateNone));
143          
144          return stats;
145       }
146       else
147       {
148          return null;
149       }
150    }
151 }
152
Popular Tags