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.10
Committed: Tue Mar 6 20:26:27 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
What can I say ? (it was his fault!)

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 tdb 1.8 * @author $Author: tdb1 $
20 tdb 1.10 * @version $Id: Register.java,v 1.9 2001/03/06 20:03:50 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 tdb 1.10 public static final String REVISION = "$Revision: 1.9 $";
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.6 _initialAlertTime = new long[numAttributes];
50 ajm 1.3 _lastAlertTimeout = new long[numAttributes];
51 ajm 1.2 _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 ajm 1.6 _initialAlertTime[x] = 0;
56 ajm 1.2 _lastThresholdLevels[x] = 0;
57 ajm 1.3 _lastAlertTimeout[x] = 0;
58 ajm 1.2 for(int y = 0; y < Alert.alertLevels.length; y++) {
59     _times[x][y] = 0;
60     }
61 ajm 1.1 }
62     }
63    
64     //---PUBLIC METHODS---
65    
66     //---PRIVATE METHODS---
67    
68     //---ACCESSOR/MUTATOR METHODS---
69    
70 ajm 1.2 /**
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 ajm 1.5 * Note that if this is setting to an OK
110     * level alert, it resets _maxLevelCount.
111     *
112 ajm 1.6 * 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 ajm 1.2 * @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 ajm 1.5 if (level == Alert.alertOK) {
122     _maxLevelCount = 0;
123 ajm 1.6 _initialAlertTime[attributeNum] = 0;
124     }
125     if (level == Alert.alertOK + 1) {
126     _initialAlertTime[attributeNum] = System.currentTimeMillis();
127 ajm 1.5 }
128 ajm 1.2 }
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 tdb 1.4 // -1.0 means we don't use an alert level
166 ajm 1.2 double threshold = -1.0;
167 tdb 1.4 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 ajm 1.2 }
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 tdb 1.4 * given level, this returns 0
191 ajm 1.2 *
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 tdb 1.4 // 0 means we don't use this value
197 ajm 1.2 long timeout = 0;
198 tdb 1.4 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 ajm 1.2 }
204 tdb 1.4 } catch (PropertyNotFoundException e) {
205     timeout = 0;
206     } catch (NumberFormatException e) {
207     timeout = 0;
208 ajm 1.2 }
209     return timeout;
210 ajm 1.1 }
211    
212 ajm 1.2 /**
213     * Either advances to the next alert level, or if
214     * the maximum alert level has been reached, simply returns
215     * that.
216     *
217 ajm 1.5 * 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 ajm 1.2 * @param attributeNum the attribute to get next alert for
222     */
223     public int getNextAlertLevel(int attributeNum) {
224 ajm 1.5 if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
225 ajm 1.2 return getLastAlertLevel(attributeNum);
226     }
227     return getLastAlertLevel(attributeNum) + 1;
228     }
229    
230     /**
231 ajm 1.3 * 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 ajm 1.6 * 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 ajm 1.2 * Advances the alert level to the next one up.
264     *
265 ajm 1.5 * 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 ajm 1.2 * @param attributeNum the attribute to advance the alert for
282     */
283     public void escalateAlert(int attributeNum) {
284 tdb 1.7 // 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 ajm 1.5 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 tdb 1.8 if (getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) {
292 ajm 1.5 _maxLevelCount++;
293 tdb 1.10 if(_maxLevelCount > reachFINALcount) {
294 tdb 1.8 setLastAlertLevel(attributeNum, Alert.alertFINAL);
295     }
296 ajm 1.5 }
297     } catch (PropertyNotFoundException e) {
298     // we NEVER reach FINAL in this case
299     } catch (NumberFormatException e) {
300     // we NEVER reach FINAL in this case
301     }
302 ajm 1.1 }
303    
304     //---ATTRIBUTES---
305    
306 ajm 1.2 /**
307     * The host this register is for
308     */
309     private String _hostname;
310    
311     /**
312     * The monitor this register is for
313     */
314     private String _monitorName;
315    
316     /**
317     * An array of last alert levels for
318     * each attribute this register is looking
319     * after.
320     */
321     private int[] _lastAlertLevels;
322    
323     /**
324     * An array of last threshold levels for
325     * each attribute this register is looking
326     * after.
327     */
328     private int[] _lastThresholdLevels;
329 ajm 1.3
330     /**
331     * An array of last alert timeout levels for
332     * each attribute this register is looking
333     * after.
334     */
335     private long[] _lastAlertTimeout;
336 ajm 1.2
337     /**
338     * An array of arrays containing
339     * time an alert of each level
340     * was last sent for each attribute.
341     */
342     private long[][] _times;
343 ajm 1.6
344     /**
345     * Initial times that an alert was first
346     * raised.
347     */
348     private long[] _initialAlertTime;
349 ajm 1.2
350     /**
351     * A reference to the configuration proxy in use
352     */
353     private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
354 ajm 1.5
355     /**
356     * The number of times the maximum level alert
357     * has occured IN A ROW, this is escalated by
358     * the escalate(int) method, and reset by the
359     * setLastAlertLevel(int, int) method
360     */
361     private int _maxLevelCount = 0;
362 ajm 1.1
363     //---STATIC ATTRIBUTES---
364    
365     }