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.7
Committed: Tue Mar 6 19:24:25 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.6: +6 -3 lines
Log Message:
Fix to stop the escalation (to a lower level) when we are already on the FINAL
level.

File Contents

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