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/MonitorSkeleton.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/MonitorSkeleton.java (file contents):
Revision 1.4 by ajm, Fri Mar 9 03:57:01 2001 UTC vs.
Revision 1.12 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 java.util.HashMap;
6 < import uk.ac.ukc.iscream.client.*;
7 < import uk.ac.ukc.iscream.core.*;
8 < import uk.ac.ukc.iscream.util.*;
9 < import uk.ac.ukc.iscream.componentmanager.*;
6 > import uk.org.iscream.cms.server.client.*;
7 > import uk.org.iscream.cms.server.core.*;
8 > import uk.org.iscream.cms.server.util.*;
9 > import uk.org.iscream.cms.server.componentmanager.*;
10  
11   /**
12   * Skeleton class for Monitors
13 + * This skeleton reads packets from a queue designated
14 + * by the extending class, it then feeds the data to the analysePacket
15 + * method, which the extending class should implement.  The class
16 + * should then handle the monitoring for that packet.
17   *
18   * @author  $Author$
19   * @version $Id$
20   */
21 < public abstract class MonitorSkeleton implements PluginMonitor {
21 > public abstract class MonitorSkeleton extends Thread implements PluginMonitor {
22  
23   //---FINAL ATTRIBUTES---
24 +
25 +    /**
26 +     * The current CVS revision of this class
27 +     */
28 +    public final String REVISION = "$Revision$";
29      
30   //---STATIC METHODS---
31  
32   //---CONSTRUCTORS---
33  
34 +    /**
35 +     * Constructs and start the monitor reading its data
36 +     */
37 +    public MonitorSkeleton() {
38 +        _logger.write(toString(), Logger.SYSINIT, "started.");
39 +        this.start();
40 +    }
41 +
42   //---PUBLIC METHODS---
43  
44 <    public abstract void analysePacket(XMLPacket packet);
44 >    /**
45 >     * Obtains data from the monitors data queue and
46 >     * passes the packet to the analysePacket method.
47 >     */
48 >    public void run() {
49 >        while(_running) {
50 >            try {
51 >                analysePacket((XMLPacket) getQueue().get(getQueueId()));
52 >            } catch (InvalidQueueException e) {
53 >                _logger.write(this.toString(), Logger.ERROR, "Unable to get queue.");
54 >            }
55 >        }
56 >    }
57 >    
58 >    /**
59 >     * Extending classes should override this method to
60 >     * analyse the given packet for the attribute
61 >     * they are responsible for.
62 >     */
63 >    protected abstract void analysePacket(XMLPacket packet);
64  
65 <    public void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
65 >    /**
66 >     * Once a Monitor has determined which threshold the given data packet
67 >     * is at, it should then call this method.  This method handles ALL
68 >     * the alerting logic to determine escalation of alerts.
69 >     * If it decides an alert needs to be send, it will send one using fireAlert.
70 >     *
71 >     * @param newThreshold the threshold that has been determined by the monitor
72 >     * @param attributeName the textual name of the attribute the monitor is responsible for
73 >     * @param reg the register that holds the current alert state for the machine/attribute
74 >     * @param source the source of the alert eg, hostname
75 >     * @param currentValue the data value for the attribute
76 >     */
77 >    protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
78          // decide what threshold level we're on, if we've changed, record that
79          if (newThreshold != reg.getLastThresholdLevel()) {
80              reg.setLastThresholdLevel(newThreshold);
# Line 74 | Line 122 | public abstract class MonitorSkeleton implements Plugi
122      }
123  
124      /**
125 <     * return the String representation of what the monitor does
125 >     * Return the String representation of what the alerter does
126 >     *
127 >     * @return the description
128       */
129      public abstract String getDescription();
130  
131  
132   //---PRIVATE METHODS---
133  
134 <    protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
134 >    /**
135 >     * Fires an alert.  This creates a new Alert object
136 >     * and populates it with the given alert information.
137 >     * It then adds the alert to the Alerter queue.
138 >     *
139 >     * This method should only be called by the processAlert method.
140 >     *
141 >     * @param reg the register holding the state values for the alert
142 >     * @param source the source of the alert eg, hostname
143 >     * @param currentValue the data value for the attribute
144 >     * @param attributeName the textual name of the attribute the alert is for
145 >     */
146 >    private void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
147          int alertLevel = reg.getLastAlertLevel();
148          int thresholdLevel = reg.getLastThresholdLevel();
149          String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel));
150          String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000);
151          // ensures we display a nice thing if its -1.0
152 <        if (thresholdLevel == -1.0) {
152 >        if (thresholdValue.equals("-1.0")) {
153              thresholdValue = "-";
154          }
155          if (alertLevel == Alert.alertOK) {
# Line 100 | Line 162 | public abstract class MonitorSkeleton implements Plugi
162  
163   //---ACCESSOR/MUTATOR METHODS---
164  
165 +    /**
166 +     * Obtain the queue which contains the data
167 +     * the Monitor is reading.
168 +     * eg, MonitorManager.getInstance().getHeartbeatQueue()
169 +     */
170 +    protected abstract Queue getQueue();
171 +    
172 +    /**
173 +     * Create a queue ID on the feeding
174 +     * data queue
175 +     */
176 +    protected int getQueueId() {
177 +        if (_qID == -1) {
178 +            _qID = getQueue().getQueue();
179 +            _logger.write(toString(), Logger.DEBUG, "Assigned Queue - " + _qID);
180 +        }
181 +        return _qID;
182 +    }
183 +
184   //---ATTRIBUTES---
185  
186 +    /**
187 +     * This holds a reference to the
188 +     * system logger that is being used.
189 +     */
190      protected Logger _logger = ReferenceManager.getInstance().getLogger();
191  
192 <    protected Queue _alerterQueue = ClientMain._alerterQueue;
192 >    /**
193 >     * A reference to the Alerter queue, into which
194 >     * all new alerts will be placed.
195 >     */
196 >    protected Queue _alerterQueue = AlerterManager.getInstance().getQueue();
197 >    
198 >    /**
199 >     * The ID of the queue the monitor will use.
200 >     * Initially -1, but initialised on first use.
201 >     */
202 >    protected int _qID = -1;
203 >    
204 >    /**
205 >     * The state of the alerter thread
206 >     */
207 >    protected boolean _running = true;
208  
209   //---STATIC ATTRIBUTES---
210  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines