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.7 by ajm, Thu Mar 22 17:56:58 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 >        try {
33 >            analysePacket((XMLPacket) getQueue().get(getQueueId()));
34 >        } catch (InvalidQueueException e) {
35 >            _logger.write(this.toString(), Logger.ERROR, "Unable to get queue.");
36 >        }
37 >    }
38 >    
39 >    protected abstract void analysePacket(XMLPacket packet);
40  
41 <    public void processAlert(int newThreshold, int attributeNum, String attributeName, Register reg, String source, String currentValue) {
41 >    protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) {
42          // decide what threshold level we're on, if we've changed, record that
43 <        if (newThreshold != reg.getLastThresholdLevel(attributeNum)) {
44 <            reg.setLastThresholdLevel(attributeNum, newThreshold);
43 >        if (newThreshold != reg.getLastThresholdLevel()) {
44 >            reg.setLastThresholdLevel(newThreshold);
45          }
46          // as long as this isn't a normal level
47 <        if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) {
47 >        if(reg.getLastThresholdLevel() != Alert.thresholdNORMAL) {
48              // if the time since the last alert is more than the time for
49              // its timeout, fire an alert, escalate the alert
50 <            long timeout = reg.getLastAlertTimeout(attributeNum);
51 <            if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
52 <                if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
53 <                    int lastAlert = reg.getLastAlertLevel(attributeNum);
54 <                    reg.escalateAlert(attributeNum);
55 <                    reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
56 <                    reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
57 <                    fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
50 >            long timeout = reg.getLastAlertTimeout();
51 >            if ((timeout > 0) && (reg.getTimeLastSent() > 0)) {
52 >                if((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) {
53 >                    int lastAlert = reg.getLastAlertLevel();
54 >                    reg.escalateAlert();
55 >                    reg.setTimeLastSent( System.currentTimeMillis());
56 >                    reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel()));
57 >                    fireAlert(reg, lastAlert, source, currentValue, attributeName);
58                  }
59              // if we don't have a timeout configured...we got STRAIGHT to the next level
60              } else {
61 <                int lastAlert = reg.getLastAlertLevel(attributeNum);
62 <                reg.escalateAlert(attributeNum);
63 <                reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
64 <                reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
65 <                fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
61 >                int lastAlert = reg.getLastAlertLevel();
62 >                reg.escalateAlert();
63 >                reg.setTimeLastSent( System.currentTimeMillis());
64 >                reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel()));
65 >                fireAlert(reg, lastAlert, source, currentValue, attributeName);
66              }
67                  
68          // we must be on ok, check the timeout value for this
# Line 58 | Line 70 | public abstract class MonitorSkeleton implements Plugi
70              // if we were on an OK alert before, then we don't do anything
71              // but if we weren't we only set OK, once the timout of the last
72              // alert has occourd
73 <            if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) {
74 <                long timeout = reg.getLastAlertTimeout(attributeNum);
75 <                if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
76 <                    if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
77 <                        int lastAlert = reg.getLastAlertLevel(attributeNum);
78 <                        reg.setLastAlertLevel(attributeNum, Alert.alertOK);
79 <                        reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
80 <                        reg.setLastAlertTimeout(attributeNum, timeout);
81 <                        fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName);
73 >            if (reg.getLastAlertLevel() != Alert.alertOK) {
74 >                long timeout = reg.getLastAlertTimeout();
75 >                if ((timeout > 0) && (reg.getTimeLastSent() > 0)) {
76 >                    if ((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) {
77 >                        int lastAlert = reg.getLastAlertLevel();
78 >                        reg.setLastAlertLevel(Alert.alertOK);
79 >                        reg.setTimeLastSent(System.currentTimeMillis());
80 >                        reg.setLastAlertTimeout(timeout);
81 >                        fireAlert(reg, lastAlert,  source, currentValue, attributeName);
82                      }
83                  }
84              }
# Line 81 | Line 93 | public abstract class MonitorSkeleton implements Plugi
93  
94   //---PRIVATE METHODS---
95  
96 <    protected void fireAlert(Register reg, int lastAlert, int attributeNum, String source, String currentValue, String attributeName) {
97 <        int alertLevel = reg.getLastAlertLevel(attributeNum);
98 <        int thresholdLevel = reg.getLastThresholdLevel(attributeNum);
96 >    protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) {
97 >        int alertLevel = reg.getLastAlertLevel();
98 >        int thresholdLevel = reg.getLastThresholdLevel();
99          String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel));
100 <        String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000);
101 <        if (thresholdLevel == Alert.thresholdNORMAL) {
100 >        String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000);
101 >        // ensures we display a nice thing if its -1.0
102 >        if (thresholdValue.equals("-1.0")) {
103              thresholdValue = "-";
104          }
105          if (alertLevel == Alert.alertOK) {
106              timeout = "0";
107          }
108 <        Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime(attributeNum));
108 >        Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime());
109          _alerterQueue.add(alert);
110          _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");
111      }
112  
113   //---ACCESSOR/MUTATOR METHODS---
114  
115 +    protected abstract Queue getQueue();
116 +    
117 +    protected int getQueueId() {
118 +        if (_qID == -1) {
119 +            _qID = getQueue().getQueue();
120 +        }
121 +        return _qID;
122 +    }
123 +
124   //---ATTRIBUTES---
125  
126      protected Logger _logger = ReferenceManager.getInstance().getLogger();
127  
128      protected Queue _alerterQueue = ClientMain._alerterQueue;
129 +    
130 +    protected int _qID = -1;
131  
132   //---STATIC ATTRIBUTES---
133  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines