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.4
Committed: Mon Mar 5 23:14:53 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.3: +22 -22 lines
Log Message:
Error catching in the configuration sections.

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     * @author $Author: ajm4 $
20 tdb 1.4 * @version $Id: Register.java,v 1.3 2001/03/04 05:23:41 ajm4 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.4 public static final String REVISION = "$Revision: 1.3 $";
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.3 _lastAlertTimeout = new long[numAttributes];
50 ajm 1.2 _times = new long[numAttributes][Alert.alertLevels.length];
51     // initialise the arrays to 0
52     for (int x = 0; x < _lastAlertLevels.length; x++) {
53     _lastAlertLevels[x] = 0;
54     _lastThresholdLevels[x] = 0;
55 ajm 1.3 _lastAlertTimeout[x] = 0;
56 ajm 1.2 for(int y = 0; y < Alert.alertLevels.length; y++) {
57     _times[x][y] = 0;
58     }
59 ajm 1.1 }
60     }
61    
62     //---PUBLIC METHODS---
63    
64     //---PRIVATE METHODS---
65    
66     //---ACCESSOR/MUTATOR METHODS---
67    
68 ajm 1.2 /**
69     * Gets the last alert level for the
70     * given attribute.
71     *
72     * @param attributeNum the attribute to get
73     *
74     * @return the last alert level
75     */
76     public int getLastAlertLevel(int attributeNum) {
77     return _lastAlertLevels[attributeNum];
78     }
79    
80     /**
81     * Sets the last threshold level for the
82     * given attribute.
83     *
84     * @param attributeNum the attribute to set
85     * @param level the new last threshold level
86     */
87     public void setLastThresholdLevel(int attributeNum, int level) {
88     _lastThresholdLevels[attributeNum] = level;
89     }
90    
91     /**
92     * Gets the last threshold level for the
93     * given attribute.
94     *
95     * @param attributeNum the attribute to get
96     *
97     * @return the last threshold level
98     */
99     public int getLastThresholdLevel(int attributeNum) {
100     return _lastThresholdLevels[attributeNum];
101     }
102    
103     /**
104     * Sets the last alert level for the
105     * given attribute.
106     *
107     * @param attributeNum the attribute to set
108     * @param level the new last alert level
109     */
110     public void setLastAlertLevel(int attributeNum, int level) {
111     _lastAlertLevels[attributeNum] = level;
112     }
113    
114     /**
115     * Gets the time an alert was sent for the
116     * given attribute at the given level.
117     *
118     * @param attributeNum the attribute to get
119     * @param level the alert level to get
120     *
121     * @return the time last sent
122     */
123     public long getTimeLastSent(int attributeNum) {
124     return _times[attributeNum][getLastAlertLevel(attributeNum)];
125     }
126    
127     /**
128     * Gets the time an alert was sent for the
129     * given attribute at the given level.
130     *
131     * @param attributeNum the attribute to get
132     * @param level the alert level to get
133     * @param value the new time
134     */
135     public void setTimeLastSent(int attributeNum, long value) {
136     _times[attributeNum][getLastAlertLevel(attributeNum)] = value;
137     }
138    
139     /**
140     * Gets the threshold value for the given
141     * level of alert.
142     *
143     * If there is no alert threshold for a
144     * given level, this returns -1.0
145     *
146     * @param level the alert level
147     */
148     public double getThreshold(int level) {
149 tdb 1.4 // -1.0 means we don't use an alert level
150 ajm 1.2 double threshold = -1.0;
151 tdb 1.4 try {
152     String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
153     threshold = Double.parseDouble(thresholdString);
154     } catch (PropertyNotFoundException e) {
155     threshold = -1.0;
156     } catch (NumberFormatException e) {
157     threshold = -1.0;
158 ajm 1.2 }
159     return threshold;
160     }
161    
162     /**
163     * Gets the alert timeout value for the given
164     * level of alert. This value is in millis,
165     * and is converted from the value in the config,
166     * which should be seconds.
167     *
168     * Note that this is dependant on the threshold value
169     * given, the timeout is obatined from the config, then
170     * divided by the threshold value, this allows alerts to
171     * progress faster should a higher threshold value be passed
172     *
173     * If there is no alert timeout for a
174 tdb 1.4 * given level, this returns 0
175 ajm 1.2 *
176     * @param level the alert level
177     * @param thresholdLevel the threshold leve we are on
178     */
179     public long getAlertTimeout(int level, int attributeNum) {
180 tdb 1.4 // 0 means we don't use this value
181 ajm 1.2 long timeout = 0;
182 tdb 1.4 try {
183     String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
184     int threshold = getLastThresholdLevel(attributeNum);
185     if (threshold > 0) {
186     timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
187 ajm 1.2 }
188 tdb 1.4 } catch (PropertyNotFoundException e) {
189     timeout = 0;
190     } catch (NumberFormatException e) {
191     timeout = 0;
192 ajm 1.2 }
193     return timeout;
194 ajm 1.1 }
195    
196 ajm 1.2 /**
197     * Either advances to the next alert level, or if
198     * the maximum alert level has been reached, simply returns
199     * that.
200     *
201     * @param attributeNum the attribute to get next alert for
202     */
203     public int getNextAlertLevel(int attributeNum) {
204     if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 1)) {
205     return getLastAlertLevel(attributeNum);
206     }
207     return getLastAlertLevel(attributeNum) + 1;
208     }
209    
210     /**
211 ajm 1.3 * Gets the timeout value of the last alert
212     * sent
213     *
214     * @param attrubuteNum the attribute to get the last timeout for
215     * @return the last timeout value
216     */
217     public long getLastAlertTimeout(int attributeNum) {
218     return _lastAlertTimeout[attributeNum];
219     }
220    
221     /**
222     * Sets the timeout value of the last alert
223     * sent
224     *
225     * @param attrubuteNum the attribute to get the last timeout for
226     * @param timeout the new value
227     */
228     public void setLastAlertTimeout(int attributeNum, long timeout) {
229     _lastAlertTimeout[attributeNum] = timeout;
230     }
231    
232     /**
233 ajm 1.2 * Advances the alert level to the next one up.
234     *
235     * @param attributeNum the attribute to advance the alert for
236     */
237     public void escalateAlert(int attributeNum) {
238     setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
239 ajm 1.1 }
240    
241     //---ATTRIBUTES---
242    
243 ajm 1.2 /**
244     * The host this register is for
245     */
246     private String _hostname;
247    
248     /**
249     * The monitor this register is for
250     */
251     private String _monitorName;
252    
253     /**
254     * An array of last alert levels for
255     * each attribute this register is looking
256     * after.
257     */
258     private int[] _lastAlertLevels;
259    
260     /**
261     * An array of last threshold levels for
262     * each attribute this register is looking
263     * after.
264     */
265     private int[] _lastThresholdLevels;
266 ajm 1.3
267     /**
268     * An array of last alert timeout levels for
269     * each attribute this register is looking
270     * after.
271     */
272     private long[] _lastAlertTimeout;
273 ajm 1.2
274     /**
275     * An array of arrays containing
276     * time an alert of each level
277     * was last sent for each attribute.
278     */
279     private long[][] _times;
280    
281     /**
282     * A reference to the configuration proxy in use
283     */
284     private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
285 ajm 1.1
286     //---STATIC ATTRIBUTES---
287    
288     }