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.11 by ajm, Fri Mar 9 03:30:54 2001 UTC vs.
Revision 1.17 by tdb, Tue May 29 17:02:34 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client;
2 > package uk.org.iscream.cms.server.client;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.componentmanager.*;
5 > import uk.org.iscream.cms.server.util.*;
6 > import uk.org.iscream.cms.server.componentmanager.*;
7  
8   /**
9   * The Register class holds theshold values,
# Line 34 | Line 34 | public class Register {
34      /**
35       * Construct a Register with the hostname and monitorName
36       * (for obtaining the threshold values).
37 +     * This constructs a generic register for a specific monitor.
38       *
39       * @param hostname the hostname this register is for
40       * @param monitorName the monitor this register is for
40
41       */
42      public Register(String hostname, String monitorName) {
43 +        this(hostname, monitorName, null);    
44 +    }
45 +
46 +    /**
47 +     * Construct a Register with the hostname and monitorName
48 +     * (for obtaining the threshold values).
49 +     * This constructs a register for a specific attribute check
50 +     * by a monitor.
51 +     *
52 +     * @param hostname the hostname this register is for
53 +     * @param monitorName the monitor this register is for
54 +     * @param attributeName the specific attribute this register is for
55 +     */
56 +    public Register(String hostname, String monitorName, String attributeName) {
57          _hostname = hostname;
58          _monitorName = monitorName;
59 +        _attributeName = attributeName;
60          _lastAlertLevel = 0;
61          _lastThresholdLevel = 0;
62          _initialAlertTime= 0;
# Line 52 | Line 67 | public class Register {
67              _times[x] = 0;
68          }
69      }
70 +        
71  
72   //---PUBLIC METHODS---
73  
74   //---PRIVATE METHODS---
75  
76 +    /**
77 +     * Obtains a threshold value from the configuration for a given level.
78 +     * The attribute name specifies which property to get.
79 +     * eg, attributeName = idle it will look for
80 +     *     Monitor.<monitor name>.idle.threshold.<alert level>
81 +     * eg, attributeName = null
82 +     *     Monitor.<monitor name>.threshold.<alert level>
83 +     *
84 +     * Note that if its null, this will get the threshold for the monitor
85 +     * as a whole, not the specific attribute.
86 +     *
87 +     * @param level the alert level to get the attribute for
88 +     * @param attributeName the attribute to get the threshold for
89 +     *
90 +     * @return the threshold obtained
91 +     */    
92 +    private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException {
93 +        String temp = "";
94 +        if (attributeName != null) {
95 +            temp = "." + attributeName;
96 +        }
97 +        return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]);
98 +    }
99 +
100   //---ACCESSOR/MUTATOR METHODS---
101      
102      /**
# Line 102 | Line 142 | public class Register {
142          _lastAlertLevel = level;
143          if (level == Alert.alertOK) {
144              _maxLevelCount = 0;
145 <            _initialAlertTime = 0;
145 >            // we won't do this, so OK's still have the initialAlertTime
146 >            // of the original alert they're OK'ing
147 >            //_initialAlertTime = 0;
148          }
149          if (level == Alert.alertOK + 1) {
150              _initialAlertTime = System.currentTimeMillis();
# Line 143 | Line 185 | public class Register {
185          // -1.0 means we don't use an alert level
186          double threshold = -1.0;
187          try {
188 <            String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
188 >            String thresholdString = "";
189 >            try {
190 >                thresholdString = getThresholdConfig(level, _attributeName);
191 >            } catch (PropertyNotFoundException e) {
192 >                thresholdString = getThresholdConfig(level, null);
193 >            }
194              threshold = Double.parseDouble(thresholdString);
195          } catch (PropertyNotFoundException e) {
196              threshold = -1.0;
# Line 159 | Line 206 | public class Register {
206       * and is converted from the value in the config,
207       * which should be seconds.
208       *
209 +     * Note that if the alert timeout for the current monitor
210 +     * is not configured, it will try to obtain the default
211 +     * timeout for all Monitor's.  If there is no alert timeout
212 +     * for either the monitor or a default setting this returns 0.
213 +     *
214       * Note that this is dependant on the threshold value
215       * given, the timeout is obatined from the config, then
216       * divided by the threshold value, this allows alerts to
217       * progress faster should a higher threshold value be passed
218       *
167     * If there is no alert timeout for a
168     * given level, this returns 0
169     *
219       * @param level the alert level
220       * @param thresholdLevel the threshold leve we are on
221       */
# Line 174 | Line 223 | public class Register {
223          // 0 means we don't use this value
224          long timeout = 0;
225          try {
226 <            String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
226 >            String timeoutString;
227 >            try {
228 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
229 >            } catch (PropertyNotFoundException e) {
230 >                // if there is no timeout for the monitor
231 >                // check for a default
232 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor.alertTimeout." + Alert.alertLevels[level]);
233 >            }    
234              int threshold = getLastThresholdLevel();
235              if (threshold > 0) {
236                  timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
# Line 285 | Line 341 | public class Register {
341       * The monitor this register is for
342       */
343      private String _monitorName;
344 +    
345 +    /**
346 +     * The attribute name, as obtained from
347 +     * the configuration.
348 +     * eg, idle or /var
349 +     */
350 +    private String _attributeName;
351  
352      /**
353       * An array of last alert levels for

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines