ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/Register.java
Revision: 1.5
Committed: Tue Mar 6 01:40:24 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.4: +51 -4 lines
Log Message:
Now has support for reaching the FINAL alert level.
This counts the number of times the highest alert level has been
reached, and then escalates to a FINAL if it exceeds
reachFINALcount.  If that value isn't configured, or is mis-configured, it will
ignore FINAL's.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.client;
3    
4     //---IMPORTS---
5     import uk.ac.ukc.iscream.util.*;
6 tdb 1.4 import uk.ac.ukc.iscream.componentmanager.*;
7 ajm 1.1
8     /**
9 ajm 1.2 * The Register class holds theshold values,
10     * the last level of alert for each attribute for a monitor
11     * and the time of last alert sent for each alert level for
12     * each attribute in this register.
13 ajm 1.1 *
14 ajm 1.2 * This class is used by monitor classes so they can determine
15     * how often they should send alerts when breaching alert levels.
16     * It also stores (and keeps uptodate (via the configuration proxy)
17     * the threshold values for the monitor.
18     *
19 ajm 1.5 * @author $Author: tdb1 $
20     * @version $Id: Register.java,v 1.4 2001/03/05 23:14:53 tdb1 Exp $
21 ajm 1.1 */
22     public class Register {
23    
24     //---FINAL ATTRIBUTES---
25    
26     /**
27     * The current CVS revision of this class
28     */
29 ajm 1.5 public static final String REVISION = "$Revision: 1.4 $";
30 ajm 1.1
31     //---STATIC METHODS---
32    
33     //---CONSTRUCTORS---
34    
35     /**
36 ajm 1.2 * Construct a Register with the hostname and monitorName
37     * (for obtaining the threshold values), and the number of
38     * attributes we are keeping track of.
39 ajm 1.1 *
40 ajm 1.2 * @param hostname the hostname this register is for
41     * @param monitorName the monitor this register is for
42     * @param numAttributes the number of attributes to track
43 ajm 1.1 */
44 ajm 1.2 public Register(String hostname, String monitorName, int numAttributes) {
45     _hostname = hostname;
46     _monitorName = monitorName;
47     _lastAlertLevels = new int[numAttributes];
48     _lastThresholdLevels = new int[numAttributes];
49 ajm 1.3 _lastAlertTimeout = new long[numAttributes];
50 ajm 1.2 _times = new long[numAttributes][Alert.alertLevels.length];
51     // initialise the arrays to 0
52     for (int x = 0; x < _lastAlertLevels.length; x++) {
53     _lastAlertLevels[x] = 0;
54     _lastThresholdLevels[x] = 0;
55 ajm 1.3 _lastAlertTimeout[x] = 0;
56 ajm 1.2 for(int y = 0; y < Alert.alertLevels.length; y++) {
57     _times[x][y] = 0;
58     }
59 ajm 1.1 }
60     }
61    
62     //---PUBLIC METHODS---
63    
64     //---PRIVATE METHODS---
65    
66     //---ACCESSOR/MUTATOR METHODS---
67    
68 ajm 1.2 /**
69     * Gets the last alert level for the
70     * given attribute.
71     *
72     * @param attributeNum the attribute to get
73     *
74     * @return the last alert level
75     */
76     public int getLastAlertLevel(int attributeNum) {
77     return _lastAlertLevels[attributeNum];
78     }
79    
80     /**
81     * Sets the last threshold level for the
82     * given attribute.
83     *
84     * @param attributeNum the attribute to set
85     * @param level the new last threshold level
86     */
87     public void setLastThresholdLevel(int attributeNum, int level) {
88     _lastThresholdLevels[attributeNum] = level;
89     }
90    
91     /**
92     * Gets the last threshold level for the
93     * given attribute.
94     *
95     * @param attributeNum the attribute to get
96     *
97     * @return the last threshold level
98     */
99     public int getLastThresholdLevel(int attributeNum) {
100     return _lastThresholdLevels[attributeNum];
101     }
102    
103     /**
104     * Sets the last alert level for the
105     * given attribute.
106     *
107 ajm 1.5 * Note that if this is setting to an OK
108     * level alert, it resets _maxLevelCount.
109     *
110 ajm 1.2 * @param attributeNum the attribute to set
111     * @param level the new last alert level
112     */
113     public void setLastAlertLevel(int attributeNum, int level) {
114     _lastAlertLevels[attributeNum] = level;
115 ajm 1.5 if (level == Alert.alertOK) {
116     _maxLevelCount = 0;
117     }
118 ajm 1.2 }
119    
120     /**
121     * Gets the time an alert was sent for the
122     * given attribute at the given level.
123     *
124     * @param attributeNum the attribute to get
125     * @param level the alert level to get
126     *
127     * @return the time last sent
128     */
129     public long getTimeLastSent(int attributeNum) {
130     return _times[attributeNum][getLastAlertLevel(attributeNum)];
131     }
132    
133     /**
134     * Gets the time an alert was sent for the
135     * given attribute at the given level.
136     *
137     * @param attributeNum the attribute to get
138     * @param level the alert level to get
139     * @param value the new time
140     */
141     public void setTimeLastSent(int attributeNum, long value) {
142     _times[attributeNum][getLastAlertLevel(attributeNum)] = value;
143     }
144    
145     /**
146     * Gets the threshold value for the given
147     * level of alert.
148     *
149     * If there is no alert threshold for a
150     * given level, this returns -1.0
151     *
152     * @param level the alert level
153     */
154     public double getThreshold(int level) {
155 tdb 1.4 // -1.0 means we don't use an alert level
156 ajm 1.2 double threshold = -1.0;
157 tdb 1.4 try {
158     String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
159     threshold = Double.parseDouble(thresholdString);
160     } catch (PropertyNotFoundException e) {
161     threshold = -1.0;
162     } catch (NumberFormatException e) {
163     threshold = -1.0;
164 ajm 1.2 }
165     return threshold;
166     }
167    
168     /**
169     * Gets the alert timeout value for the given
170     * level of alert. This value is in millis,
171     * and is converted from the value in the config,
172     * which should be seconds.
173     *
174     * Note that this is dependant on the threshold value
175     * given, the timeout is obatined from the config, then
176     * divided by the threshold value, this allows alerts to
177     * progress faster should a higher threshold value be passed
178     *
179     * If there is no alert timeout for a
180 tdb 1.4 * given level, this returns 0
181 ajm 1.2 *
182     * @param level the alert level
183     * @param thresholdLevel the threshold leve we are on
184     */
185     public long getAlertTimeout(int level, int attributeNum) {
186 tdb 1.4 // 0 means we don't use this value
187 ajm 1.2 long timeout = 0;
188 tdb 1.4 try {
189     String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
190     int threshold = getLastThresholdLevel(attributeNum);
191     if (threshold > 0) {
192     timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
193 ajm 1.2 }
194 tdb 1.4 } catch (PropertyNotFoundException e) {
195     timeout = 0;
196     } catch (NumberFormatException e) {
197     timeout = 0;
198 ajm 1.2 }
199     return timeout;
200 ajm 1.1 }
201    
202 ajm 1.2 /**
203     * Either advances to the next alert level, or if
204     * the maximum alert level has been reached, simply returns
205     * that.
206     *
207 ajm 1.5 * Note this method will NEVER reach the last alert level
208     * in the list, this is assumed to be FINAL, and special
209     * logic is in place to handle that.
210     *
211 ajm 1.2 * @param attributeNum the attribute to get next alert for
212     */
213     public int getNextAlertLevel(int attributeNum) {
214 ajm 1.5 if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
215 ajm 1.2 return getLastAlertLevel(attributeNum);
216     }
217     return getLastAlertLevel(attributeNum) + 1;
218     }
219    
220     /**
221 ajm 1.3 * Gets the timeout value of the last alert
222     * sent
223     *
224     * @param attrubuteNum the attribute to get the last timeout for
225     * @return the last timeout value
226     */
227     public long getLastAlertTimeout(int attributeNum) {
228     return _lastAlertTimeout[attributeNum];
229     }
230    
231     /**
232     * Sets the timeout value of the last alert
233     * sent
234     *
235     * @param attrubuteNum the attribute to get the last timeout for
236     * @param timeout the new value
237     */
238     public void setLastAlertTimeout(int attributeNum, long timeout) {
239     _lastAlertTimeout[attributeNum] = timeout;
240     }
241    
242     /**
243 ajm 1.2 * Advances the alert level to the next one up.
244     *
245 ajm 1.5 * This keeps track of the number of the number
246     * of times the highest NON-FINAL alert level
247     * has been reached. Note this isn't a specific
248     * level, just the highest, so you could configure
249     * more levels and not affect this.
250     *
251     * If the count exceeds the number of times
252     * set in the configuration, it escalates to
253     * a FINAL alert if we're using FINAL's.
254     *
255     * It determines if to use FINAL's from the config
256     * entry reachFINALcount, when the count exceeds
257     * this value, it escalates to a FINAL. If that attribute
258     * is mis-read or is not configured. It will NEVER reach
259     * a FINAL.
260     *
261 ajm 1.2 * @param attributeNum the attribute to advance the alert for
262     */
263     public void escalateAlert(int attributeNum) {
264     setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
265 ajm 1.5 try {
266     // note if we fail to get this value, we won't process the res of this
267     int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount"));
268     if ((getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) && (_maxLevelCount < reachFINALcount) ) {
269     _maxLevelCount++;
270     } else {
271     setLastAlertLevel(attributeNum, Alert.alertFINAL);
272     }
273     } catch (PropertyNotFoundException e) {
274     // we NEVER reach FINAL in this case
275     } catch (NumberFormatException e) {
276     // we NEVER reach FINAL in this case
277     }
278 ajm 1.1 }
279    
280     //---ATTRIBUTES---
281    
282 ajm 1.2 /**
283     * The host this register is for
284     */
285     private String _hostname;
286    
287     /**
288     * The monitor this register is for
289     */
290     private String _monitorName;
291    
292     /**
293     * An array of last alert levels for
294     * each attribute this register is looking
295     * after.
296     */
297     private int[] _lastAlertLevels;
298    
299     /**
300     * An array of last threshold levels for
301     * each attribute this register is looking
302     * after.
303     */
304     private int[] _lastThresholdLevels;
305 ajm 1.3
306     /**
307     * An array of last alert timeout levels for
308     * each attribute this register is looking
309     * after.
310     */
311     private long[] _lastAlertTimeout;
312 ajm 1.2
313     /**
314     * An array of arrays containing
315     * time an alert of each level
316     * was last sent for each attribute.
317     */
318     private long[][] _times;
319    
320     /**
321     * A reference to the configuration proxy in use
322     */
323     private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
324 ajm 1.5
325     /**
326     * The number of times the maximum level alert
327     * has occured IN A ROW, this is escalated by
328     * the escalate(int) method, and reset by the
329     * setLastAlertLevel(int, int) method
330     */
331     private int _maxLevelCount = 0;
332 ajm 1.1
333     //---STATIC ATTRIBUTES---
334    
335     }