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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Heartbeat__Monitor.java (file contents):
Revision 1.11 by tdb, Wed Mar 7 21:38:14 2001 UTC vs.
Revision 1.14 by ajm, Thu Mar 22 21:36:26 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client.monitors;
2 > package uk.org.iscream.client.monitors;
3  
4   //---IMPORTS---
5   import java.util.HashMap;
6   import java.util.Iterator;
7 < import uk.ac.ukc.iscream.client.*;
8 < import uk.ac.ukc.iscream.core.*;
9 < import uk.ac.ukc.iscream.util.*;
10 < import uk.ac.ukc.iscream.componentmanager.*;
7 > import uk.org.iscream.client.*;
8 > import uk.org.iscream.core.*;
9 > import uk.org.iscream.util.*;
10 > import uk.org.iscream.componentmanager.*;
11  
12   /**
13   * This Monitor watches heartbeats
# Line 15 | Line 15 | import uk.ac.ukc.iscream.componentmanager.*;
15   * @author  $Author$
16   * @version $Id$
17   */
18 < public class Heartbeat__Monitor extends MonitorSkeleton implements Runnable {
18 > public class Heartbeat__Monitor extends MonitorSkeleton {
19  
20   //---FINAL ATTRIBUTES---
21  
# Line 34 | Line 34 | public class Heartbeat__Monitor extends MonitorSkeleto
34  
35      public Heartbeat__Monitor() {
36          new Thread(this).start();
37 +        new HeartbeatWorker().start();
38      }
39  
40   //---PUBLIC METHODS---
41      
42 <    public void run() {
43 <        ConfigurationProxy cp = ConfigurationProxy.getInstance();
44 <        while(true) {
44 <            // this cycle period of this monitor's checks
45 <            int checkPeriod = 0;
46 <            try {
47 <                checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod"));
48 <            } catch (PropertyNotFoundException e) {
49 <                checkPeriod = DEFAULT_CHECK_PERIOD;
50 <                _logger.write(toString(), Logger.WARNING, "Monitor.Heartbeat.checkPeriod value unavailable using default of " + checkPeriod + " seconds");
51 <            } catch (NumberFormatException e) {
52 <                checkPeriod = DEFAULT_CHECK_PERIOD;
53 <                _logger.write(toString(), Logger.WARNING, "Erronous Monitor.Heartbeat.checkPeriod value in configuration using default of " + checkPeriod + " seconds");
54 <            }
55 <            
42 >    public void analysePacket(XMLPacket packet) {
43 >        String source = packet.getParam("packet.attributes.machine_name");
44 >        if (!_hosts.containsKey(source)) {
45              synchronized(this) {
46 <                // perform the checks (use HB hash, although they *should* be the same)
47 <                Iterator i = _hosts.keySet().iterator();
48 <                while(i.hasNext()) {
60 <                    // get host
61 <                    String source = (String) i.next();
62 <                    // check it
63 <                    boolean remove = analyseHB(source);
64 <                    if(remove) {
65 <                        i.remove();
66 <                    }
67 <                }
46 >                HashMap registerHash = new HashMap();
47 >                registerHash.put(source, new Register(source, _name));
48 >                _hosts.put(source, new HeartbeatHolder(registerHash));
49              }
69            
70            // wait a while
71            try {Thread.sleep(checkPeriod * 1000);} catch (InterruptedException e) {}
50          }
51 +        HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source);
52 +        lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000);
53      }
54      
75    public void analysePacket(XMLPacket packet) {
76        if (packet.getParam("packet.attributes.type").equals("heartbeat")) {
77            String source = packet.getParam("packet.attributes.machine_name");
78            if (!_hosts.containsKey(source)) {
79                synchronized(this) {
80                    HashMap registerHash = new HashMap();
81                    registerHash.put(source, new Register(source, _name, 1));
82                    _hosts.put(source, new HeartbeatHolder(registerHash));
83                }
84            }
85            HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source);
86            lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000);
87        }
88    }
89    
55      /**
56       * Overrides the {@link java.lang.Object#toString() Object.toString()}
57       * method to provide clean logging (every class should have this).
58       *
59 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
59 >     * This uses the uk.org.iscream.util.NameFormat class
60       * to format the toString()
61       *
62       * @return the name of this class and its CVS revision
# Line 146 | Line 111 | public class Heartbeat__Monitor extends MonitorSkeleto
111          int newThreshold = checkAttributeThreshold(timeSinceExpectedHB, reg);
112          
113          // process the alert
114 <        processAlert(newThreshold, 0, "Heartbeat", reg, source, String.valueOf(timeSinceExpectedHB));
114 >        processAlert(newThreshold, "Heartbeat", reg, source, String.valueOf(timeSinceExpectedHB));
115          
116 <        if(reg.getLastAlertLevel(0) == Alert.alertFINAL) {
116 >        if(reg.getLastAlertLevel() == Alert.alertFINAL) {
117              return true;
118          }
119          return false;
# Line 167 | Line 132 | public class Heartbeat__Monitor extends MonitorSkeleto
132  
133   //---ACCESSOR/MUTATOR METHODS---
134  
135 +    protected Queue getQueue() {
136 +        return MonitorManager.getInstance().getHeartbeatQueue();
137 +    }
138 +    
139   //---ATTRIBUTES---
140  
141      /**
# Line 211 | Line 180 | public class Heartbeat__Monitor extends MonitorSkeleto
180          
181          private long _lastHeartbeat;
182          private HashMap _registerHash;
183 <    }  
183 >    }
184 >    
185 >    private class HeartbeatWorker extends Thread {
186 >        
187 >        public void run() {
188 >            ConfigurationProxy cp = ConfigurationProxy.getInstance();
189 >            while(true) {
190 >                // this cycle period of this monitor's checks
191 >                int checkPeriod = 0;
192 >                try {
193 >                    checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod"));
194 >                } catch (PropertyNotFoundException e) {
195 >                    checkPeriod = DEFAULT_CHECK_PERIOD;
196 >                    _logger.write(this.toString(), Logger.WARNING, "Monitor.Heartbeat.checkPeriod value unavailable using default of " + checkPeriod + " seconds");
197 >                } catch (NumberFormatException e) {
198 >                    checkPeriod = DEFAULT_CHECK_PERIOD;
199 >                    _logger.write(this.toString(), Logger.WARNING, "Erronous Monitor.Heartbeat.checkPeriod value in configuration using default of " + checkPeriod + " seconds");
200 >                }
201 >                
202 >                synchronized(this) {
203 >                    // perform the checks (use HB hash, although they *should* be the same)
204 >                    Iterator i = _hosts.keySet().iterator();
205 >                    while(i.hasNext()) {
206 >                        // get host
207 >                        String source = (String) i.next();
208 >                        // check it
209 >                        boolean remove = analyseHB(source);
210 >                        if(remove) {
211 >                            i.remove();
212 >                        }
213 >                    }
214 >                }
215 >                
216 >                // wait a while
217 >                try {Thread.sleep(checkPeriod * 1000);} catch (InterruptedException e) {}
218 >            }
219 >        }
220 >    }
221  
222   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines