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.2
Committed: Sun Mar 4 02:41:16 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.1: +214 -15 lines
Log Message:
Revamped monitoring and alert fireing mechanism.
Now takes account of timing of last alerts.
Now uses threshold value a guide to how quickly alerts should be escalated.

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