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.3 by ajm, Fri Mar 9 03:30:54 2001 UTC vs.
Revision 1.13 by tdb, Sat May 18 18:16:00 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.ac.ukc.iscream.client;
21 > package uk.org.iscream.cms.server.client;
22  
23   //---IMPORTS---
24   import java.util.HashMap;
25 < import uk.ac.ukc.iscream.client.*;
26 < import uk.ac.ukc.iscream.core.*;
27 < import uk.ac.ukc.iscream.util.*;
28 < import uk.ac.ukc.iscream.componentmanager.*;
25 > import uk.org.iscream.cms.server.client.*;
26 > import uk.org.iscream.cms.server.core.*;
27 > import uk.org.iscream.cms.server.util.*;
28 > import uk.org.iscream.cms.server.componentmanager.*;
29  
30   /**
31   * Skeleton class for Monitors
32 + * This skeleton reads packets from a queue designated
33 + * by the extending class, it then feeds the data to the analysePacket
34 + * method, which the extending class should implement.  The class
35 + * should then handle the monitoring for that packet.
36   *
37   * @author  $Author$
38   * @version $Id$
39   */
40 < public abstract class MonitorSkeleton implements PluginMonitor {
40 > public abstract class MonitorSkeleton extends Thread implements PluginMonitor {
41  
42   //---FINAL ATTRIBUTES---
43 +
44 +    /**
45 +     * The current CVS revision of this class
46 +     */
47 +    public final String REVISION = "$Revision$";
48      
49   //---STATIC METHODS---
50  
51   //---CONSTRUCTORS---
52  
53 +    /**
54 +     * Constructs and start the monitor reading its data
55 +     */
56 +    public MonitorSkeleton() {
57 +        _logger.write(toString(), Logger.SYSINIT, "started.");
58 +        this.start();
59 +    }
60 +
61   //---PUBLIC METHODS---
62  
63 <    public abstract void analysePacket(XMLPacket packet);
63 >    /**
64 >     * Obtains data from the monitors data queue and
65 >     * passes the packet to the analysePacket method.
66 >     */
67 >    public void run() {
68 >        while(_running) {
69 >            try {
70 >                analysePacket((XMLPacket) getQueue().get(getQueueId()));
71 >            } catch (InvalidQueueException e) {
72 >                _logger.write(this.toString(), Logger.ERROR, "Unable to get queue.");
73 >            }
74 >        }
75 >    }
76 >    
77 >    /**
78 >     * Extending classes should override this method to
79 >     * analyse the given packet for the attribute
80 >     * they are responsible for.
81 >     */
82 >    protected abstract void analysePacket(XMLPacket packet);
83  
84 <    public void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
84 >    /**
85 >     * Once a Monitor has determined which threshold the given data packet
86 >     * is at, it should then call this method.  This method handles ALL
87 >     * the alerting logic to determine escalation of alerts.
88 >     * If it decides an alert needs to be send, it will send one using fireAlert.
89 >     *
90 >     * @param newThreshold the threshold that has been determined by the monitor
91 >     * @param attributeName the textual name of the attribute the monitor is responsible for
92 >     * @param reg the register that holds the current alert state for the machine/attribute
93 >     * @param source the source of the alert eg, hostname
94 >     * @param currentValue the data value for the attribute
95 >     */
96 >    protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
97          // decide what threshold level we're on, if we've changed, record that
98          if (newThreshold != reg.getLastThresholdLevel()) {
99              reg.setLastThresholdLevel(newThreshold);
# Line 74 | Line 141 | public abstract class MonitorSkeleton implements Plugi
141      }
142  
143      /**
144 <     * return the String representation of what the monitor does
144 >     * Return the String representation of what the alerter does
145 >     *
146 >     * @return the description
147       */
148      public abstract String getDescription();
149  
150  
151   //---PRIVATE METHODS---
152  
153 <    protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
153 >    /**
154 >     * Fires an alert.  This creates a new Alert object
155 >     * and populates it with the given alert information.
156 >     * It then adds the alert to the Alerter queue.
157 >     *
158 >     * This method should only be called by the processAlert method.
159 >     *
160 >     * @param reg the register holding the state values for the alert
161 >     * @param source the source of the alert eg, hostname
162 >     * @param currentValue the data value for the attribute
163 >     * @param attributeName the textual name of the attribute the alert is for
164 >     */
165 >    private void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
166          int alertLevel = reg.getLastAlertLevel();
167          int thresholdLevel = reg.getLastThresholdLevel();
168          String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel));
169          String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000);
170 <        if (thresholdLevel == Alert.thresholdNORMAL) {
170 >        // ensures we display a nice thing if its -1.0
171 >        if (thresholdValue.equals("-1.0")) {
172              thresholdValue = "-";
173          }
174          if (alertLevel == Alert.alertOK) {
# Line 99 | Line 181 | public abstract class MonitorSkeleton implements Plugi
181  
182   //---ACCESSOR/MUTATOR METHODS---
183  
184 +    /**
185 +     * Obtain the queue which contains the data
186 +     * the Monitor is reading.
187 +     * eg, MonitorManager.getInstance().getHeartbeatQueue()
188 +     */
189 +    protected abstract Queue getQueue();
190 +    
191 +    /**
192 +     * Create a queue ID on the feeding
193 +     * data queue
194 +     */
195 +    protected int getQueueId() {
196 +        if (_qID == -1) {
197 +            _qID = getQueue().getQueue();
198 +            _logger.write(toString(), Logger.DEBUG, "Assigned Queue - " + _qID);
199 +        }
200 +        return _qID;
201 +    }
202 +
203   //---ATTRIBUTES---
204  
205 +    /**
206 +     * This holds a reference to the
207 +     * system logger that is being used.
208 +     */
209      protected Logger _logger = ReferenceManager.getInstance().getLogger();
210  
211 <    protected Queue _alerterQueue = ClientMain._alerterQueue;
211 >    /**
212 >     * A reference to the Alerter queue, into which
213 >     * all new alerts will be placed.
214 >     */
215 >    protected Queue _alerterQueue = AlerterManager.getInstance().getQueue();
216 >    
217 >    /**
218 >     * The ID of the queue the monitor will use.
219 >     * Initially -1, but initialised on first use.
220 >     */
221 >    protected int _qID = -1;
222 >    
223 >    /**
224 >     * The state of the alerter thread
225 >     */
226 >    protected boolean _running = true;
227  
228   //---STATIC ATTRIBUTES---
229  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines