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.2 by tdb, Wed Mar 7 23:17:02 2001 UTC vs.
Revision 1.8 by ajm, Thu Mar 22 18:28:17 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client;
2 > package uk.org.iscream.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.client.*;
7 > import uk.org.iscream.core.*;
8 > import uk.org.iscream.util.*;
9 > import uk.org.iscream.componentmanager.*;
10  
11   /**
12   * Skeleton class for Monitors
# Line 14 | Line 14 | import uk.ac.ukc.iscream.componentmanager.*;
14   * @author  $Author$
15   * @version $Id$
16   */
17 < public abstract class MonitorSkeleton implements PluginMonitor {
17 > public abstract class MonitorSkeleton extends Thread implements PluginMonitor {
18  
19   //---FINAL ATTRIBUTES---
20      
# Line 22 | Line 22 | public abstract class MonitorSkeleton implements Plugi
22  
23   //---CONSTRUCTORS---
24  
25 +    public MonitorSkeleton() {
26 +        this.start();
27 +    }
28 +
29   //---PUBLIC METHODS---
30  
31 <    public abstract void analysePacket(XMLPacket packet);
31 >    public void run() {
32 >        while(_running) {
33 >            try {
34 >                analysePacket((XMLPacket) getQueue().get(getQueueId()));
35 >            } catch (InvalidQueueException e) {
36 >                _logger.write(this.toString(), Logger.ERROR, "Unable to get queue.");
37 >            }
38 >        }
39 >    }
40 >    
41 >    protected abstract void analysePacket(XMLPacket packet);
42  
43 <    public void processAlert(int newThreshold, int attributeNum, String attributeName, Register reg, String source, String currentValue) {
43 >    protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
44          // decide what threshold level we're on, if we've changed, record that
45 <        if (newThreshold != reg.getLastThresholdLevel(attributeNum)) {
46 <            reg.setLastThresholdLevel(attributeNum, newThreshold);
45 >        if (newThreshold != reg.getLastThresholdLevel()) {
46 >            reg.setLastThresholdLevel(newThreshold);
47          }
48          // as long as this isn't a normal level
49 <        if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) {
49 >        if(reg.getLastThresholdLevel() != Alert.thresholdNORMAL) {
50              // if the time since the last alert is more than the time for
51              // its timeout, fire an alert, escalate the alert
52 <            long timeout = reg.getLastAlertTimeout(attributeNum);
53 <            if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
54 <                if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
55 <                    int lastAlert = reg.getLastAlertLevel(attributeNum);
56 <                    reg.escalateAlert(attributeNum);
57 <                    reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
58 <                    reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
59 <                    fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
52 >            long timeout = reg.getLastAlertTimeout();
53 >            if ((timeout > 0) && (reg.getTimeLastSent() > 0)) {
54 >                if((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) {
55 >                    int lastAlert = reg.getLastAlertLevel();
56 >                    reg.escalateAlert();
57 >                    reg.setTimeLastSent( System.currentTimeMillis());
58 >                    reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel()));
59 >                    fireAlert(reg, lastAlert, source, currentValue, attributeName);
60                  }
61              // if we don't have a timeout configured...we got STRAIGHT to the next level
62              } else {
63 <                int lastAlert = reg.getLastAlertLevel(attributeNum);
64 <                reg.escalateAlert(attributeNum);
65 <                reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
66 <                reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
67 <                fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
63 >                int lastAlert = reg.getLastAlertLevel();
64 >                reg.escalateAlert();
65 >                reg.setTimeLastSent( System.currentTimeMillis());
66 >                reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel()));
67 >                fireAlert(reg, lastAlert, source, currentValue, attributeName);
68              }
69                  
70          // we must be on ok, check the timeout value for this
# Line 58 | Line 72 | public abstract class MonitorSkeleton implements Plugi
72              // if we were on an OK alert before, then we don't do anything
73              // but if we weren't we only set OK, once the timout of the last
74              // alert has occourd
75 <            if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) {
76 <                long timeout = reg.getLastAlertTimeout(attributeNum);
77 <                if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
78 <                    if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
79 <                        int lastAlert = reg.getLastAlertLevel(attributeNum);
80 <                        reg.setLastAlertLevel(attributeNum, Alert.alertOK);
81 <                        reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
82 <                        reg.setLastAlertTimeout(attributeNum, timeout);
83 <                        fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
75 >            if (reg.getLastAlertLevel() != Alert.alertOK) {
76 >                long timeout = reg.getLastAlertTimeout();
77 >                if ((timeout > 0) && (reg.getTimeLastSent() > 0)) {
78 >                    if ((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) {
79 >                        int lastAlert = reg.getLastAlertLevel();
80 >                        reg.setLastAlertLevel(Alert.alertOK);
81 >                        reg.setTimeLastSent(System.currentTimeMillis());
82 >                        reg.setLastAlertTimeout(timeout);
83 >                        fireAlert(reg, lastAlert,  source, currentValue, attributeName);
84                      }
85                  }
86              }
# Line 81 | Line 95 | public abstract class MonitorSkeleton implements Plugi
95  
96   //---PRIVATE METHODS---
97  
98 <    protected void fireAlert(Register reg, int lastAlert, int attributeNum, String source, String currentValue, String attributeName) {
99 <        int alertLevel = reg.getLastAlertLevel(attributeNum);
100 <        int thresholdLevel = reg.getLastThresholdLevel(attributeNum);
98 >    protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
99 >        int alertLevel = reg.getLastAlertLevel();
100 >        int thresholdLevel = reg.getLastThresholdLevel();
101          String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel));
102 <        String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000);
103 <        if (thresholdLevel == Alert.thresholdNORMAL) {
102 >        String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000);
103 >        // ensures we display a nice thing if its -1.0
104 >        if (thresholdValue.equals("-1.0")) {
105              thresholdValue = "-";
106          }
107          if (alertLevel == Alert.alertOK) {
108              timeout = "0";
109          }
110 <        Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime(attributeNum));
110 >        Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime());
111          _alerterQueue.add(alert);
112          _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + Alert.alertLevels[alertLevel] + " on:" + attributeName + " for threshold level:" + Alert.thresholdLevels[thresholdLevel] + " at:" +  currentValue + " exceeding threshold of:" +thresholdValue + " next alert sent in:" + timeout + "secs");
113      }
114  
115   //---ACCESSOR/MUTATOR METHODS---
116  
117 +    protected abstract Queue getQueue();
118 +    
119 +    protected int getQueueId() {
120 +        if (_qID == -1) {
121 +            _qID = getQueue().getQueue();
122 +        }
123 +        return _qID;
124 +    }
125 +
126   //---ATTRIBUTES---
127  
128      protected Logger _logger = ReferenceManager.getInstance().getLogger();
129  
130      protected Queue _alerterQueue = ClientMain._alerterQueue;
131 +    
132 +    protected int _qID = -1;
133 +    
134 +    protected boolean _running = true;
135  
136   //---STATIC ATTRIBUTES---
137  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines