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.12
Committed: Wed Mar 14 23:25:29 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.11: +6 -6 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.client;
3
4 //---IMPORTS---
5 import uk.org.iscream.util.*;
6 import uk.org.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.
12 *
13 * 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 * @author $Author: ajm4 $
19 * @version $Id: Register.java,v 1.11 2001/03/09 03:30:54 ajm4 Exp $
20 */
21 public class Register {
22
23 //---FINAL ATTRIBUTES---
24
25 /**
26 * The current CVS revision of this class
27 */
28 public static final String REVISION = "$Revision: 1.11 $";
29
30 //---STATIC METHODS---
31
32 //---CONSTRUCTORS---
33
34 /**
35 * Construct a Register with the hostname and monitorName
36 * (for obtaining the threshold values).
37 *
38 * @param hostname the hostname this register is for
39 * @param monitorName the monitor this register is for
40
41 */
42 public Register(String hostname, String monitorName) {
43 _hostname = hostname;
44 _monitorName = monitorName;
45 _lastAlertLevel = 0;
46 _lastThresholdLevel = 0;
47 _initialAlertTime= 0;
48 _lastAlertTimeout = 0;
49 _times = new long[Alert.alertLevels.length];
50 // initialise the arrays to 0
51 for(int x = 0; x < Alert.alertLevels.length; x++) {
52 _times[x] = 0;
53 }
54 }
55
56 //---PUBLIC METHODS---
57
58 //---PRIVATE METHODS---
59
60 //---ACCESSOR/MUTATOR METHODS---
61
62 /**
63 * Gets the last alert level
64 *
65 * @return the last alert level
66 */
67 public int getLastAlertLevel() {
68 return _lastAlertLevel;
69 }
70
71 /**
72 * Sets the last threshold level
73 *
74 * @param level the new last threshold level
75 */
76 public void setLastThresholdLevel(int level) {
77 _lastThresholdLevel = level;
78 }
79
80 /**
81 * Gets the last threshold level
82 *
83 * @return the last threshold level
84 */
85 public int getLastThresholdLevel() {
86 return _lastThresholdLevel;
87 }
88
89 /**
90 * Sets the last alert level
91 *
92 * Note that if this is setting to an OK
93 * level alert, it resets _maxLevelCount.
94 *
95 * 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 * @param level the new last alert level
100 */
101 public void setLastAlertLevel(int level) {
102 _lastAlertLevel = level;
103 if (level == Alert.alertOK) {
104 _maxLevelCount = 0;
105 _initialAlertTime = 0;
106 }
107 if (level == Alert.alertOK + 1) {
108 _initialAlertTime = System.currentTimeMillis();
109 }
110 }
111
112 /**
113 * Gets the time an alert was sent at the given level.
114 *
115 * @param level the alert level to get
116 *
117 * @return the time last sent
118 */
119 public long getTimeLastSent() {
120 return _times[getLastAlertLevel()];
121 }
122
123 /**
124 * Gets the time an alert was sent at the given level.
125 *
126 * @param level the alert level to get
127 * @param value the new time
128 */
129 public void setTimeLastSent(long value) {
130 _times[getLastAlertLevel()] = value;
131 }
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 // -1.0 means we don't use an alert level
144 double threshold = -1.0;
145 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 }
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 * given level, this returns 0
169 *
170 * @param level the alert level
171 * @param thresholdLevel the threshold leve we are on
172 */
173 public long getAlertTimeout(int level) {
174 // 0 means we don't use this value
175 long timeout = 0;
176 try {
177 String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
178 int threshold = getLastThresholdLevel();
179 if (threshold > 0) {
180 timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
181 }
182 } catch (PropertyNotFoundException e) {
183 timeout = 0;
184 } catch (NumberFormatException e) {
185 timeout = 0;
186 }
187 return timeout;
188 }
189
190 /**
191 * Either advances to the next alert level, or if
192 * the maximum alert level has been reached, simply returns
193 * that.
194 *
195 * 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 */
200 public int getNextAlertLevel() {
201 if((getLastAlertLevel() + 1) > (Alert.alertLevels.length - 2)) {
202 return getLastAlertLevel();
203 }
204 return getLastAlertLevel() + 1;
205 }
206
207 /**
208 * Gets the timeout value of the last alert
209 * sent
210 *
211 * @return the last timeout value
212 */
213 public long getLastAlertTimeout() {
214 return _lastAlertTimeout;
215 }
216
217 /**
218 * Sets the timeout value of the last alert
219 * sent
220 *
221 * @param timeout the new value
222 */
223 public void setLastAlertTimeout(long timeout) {
224 _lastAlertTimeout = timeout;
225 }
226
227 /**
228 * Returns the time that the first alert was sent
229 * for an attribute that has passed a threshold value
230 *
231 */
232 public long getInitialAlertTime() {
233 return _initialAlertTime;
234 }
235
236 /**
237 * Advances the alert level to the next one up.
238 *
239 * 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 */
256 public void escalateAlert() {
257 // don't escalate if we're already on the last alert
258 if(getLastAlertLevel() != Alert.alertLevels.length -1) {
259 setLastAlertLevel(getNextAlertLevel());
260 }
261 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 if (getLastAlertLevel() == Alert.alertLevels.length - 2) {
265 _maxLevelCount++;
266 if(_maxLevelCount > reachFINALcount) {
267 setLastAlertLevel(Alert.alertFINAL);
268 }
269 }
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 }
276
277 //---ATTRIBUTES---
278
279 /**
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 private int _lastAlertLevel;
295
296 /**
297 * An array of last threshold levels for
298 * each attribute this register is looking
299 * after.
300 */
301 private int _lastThresholdLevel;
302
303 /**
304 * An array of last alert timeout levels for
305 * each attribute this register is looking
306 * after.
307 */
308 private long _lastAlertTimeout;
309
310 /**
311 * An array of arrays containing
312 * time an alert of each level
313 * was last sent for each attribute.
314 */
315 private long[] _times;
316
317 /**
318 * Initial times that an alert was first
319 * raised.
320 */
321 private long _initialAlertTime;
322
323 /**
324 * A reference to the configuration proxy in use
325 */
326 private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
327
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
336 //---STATIC ATTRIBUTES---
337
338 }