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.11
Committed: Fri Mar 9 03:30:54 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.10: +56 -83 lines
Log Message:
TOTALLY re-wrote the Register class and made appropriate changes thoughout.  It
is now much more obvious what is going on in many places.

The problem was probably caused by doing CPU as a first monitor and hard coding
the number of attributes a Register stores.  Now if a monitor wants to store
multiple attributes, it has to do that itself.  This makes alot of things
much more readable and inteligable as a result.

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