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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/Register.java (file contents):
Revision 1.3 by ajm, Sun Mar 4 05:23:41 2001 UTC vs.
Revision 1.7 by tdb, Tue Mar 6 19:24:25 2001 UTC

# Line 3 | Line 3 | package uk.ac.ukc.iscream.client;
3  
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.componentmanager.ConfigurationProxy;
6 > import uk.ac.ukc.iscream.componentmanager.*;
7  
8   /**
9   * The Register class holds theshold values,
# Line 46 | Line 46 | public class Register {
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++) {
# Line 104 | Line 106 | public class Register {
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      /**
# Line 146 | Line 162 | public class Register {
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 <        String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
168 <        if(thresholdString != null) {
169 <            try {
170 <                threshold = Double.parseDouble(thresholdString);
171 <            } catch (NumberFormatException e) {
172 <                // -1.0 means we don't use an alert level
173 <                threshold = -1.0;
157 <            }
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      }
# Line 171 | Line 187 | public class Register {
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 -1.0
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 <        String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
199 <        if(timeoutString != null) {
200 <            try {
201 <                int threshold = getLastThresholdLevel(attributeNum);
202 <                if (threshold > 0) {
186 <                    timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
187 <                }
188 <            } catch (NumberFormatException e) {
189 <                // -1.0 means we don't use this value
190 <                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      }
# Line 198 | Line 214 | public class Register {
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 - 1)) {
224 >        if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
225              return getLastAlertLevel(attributeNum);
226          }
227          return getLastAlertLevel(attributeNum) + 1;
# Line 230 | Line 250 | public class Register {
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 <        setLastAlertLevel(attributeNum, getNextAlertLevel(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---
# Line 277 | Line 339 | public class Register {
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines