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.18 by tdb, Fri Mar 23 02:32:49 2001 UTC vs.
Revision 1.21 by tdb, Mon Nov 26 12:56:33 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.org.iscream.client.monitors;
2 > package uk.org.iscream.cms.server.client.monitors;
3  
4   //---IMPORTS---
5   import java.util.HashMap;
6   import java.util.Iterator;
7 < import uk.org.iscream.client.*;
8 < import uk.org.iscream.core.*;
9 < import uk.org.iscream.util.*;
10 < import uk.org.iscream.componentmanager.*;
7 > import java.util.StringTokenizer;
8 > import uk.org.iscream.cms.server.client.*;
9 > import uk.org.iscream.cms.server.core.*;
10 > import uk.org.iscream.cms.server.util.*;
11 > import uk.org.iscream.cms.server.componentmanager.*;
12  
13   /**
14   * This Monitor watches heartbeats.
# Line 51 | Line 52 | public class Heartbeat__Monitor extends MonitorSkeleto
52       */
53      public Heartbeat__Monitor() {
54          super();
55 +        createInitialHosts();
56          new HeartbeatWorker().start();
57      }
58  
# Line 77 | Line 79 | public class Heartbeat__Monitor extends MonitorSkeleto
79       * Overrides the {@link java.lang.Object#toString() Object.toString()}
80       * method to provide clean logging (every class should have this).
81       *
82 <     * This uses the uk.org.iscream.util.NameFormat class
82 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
83       * to format the toString()
84       *
85       * @return the name of this class and its CVS revision
# Line 116 | Line 118 | public class Heartbeat__Monitor extends MonitorSkeleto
118          }
119          return Alert.thresholdNORMAL;
120      }
121 +    
122 +    /**
123 +     * Gets an initial list of hosts from the config
124 +     * and adds a fake set of heartbeats for them.
125 +     * If the hosts don't respond within the timeout
126 +     * period an alert will be raised.
127 +     *
128 +     * The effect of this is to allow us to know about
129 +     * hosts which weren't on when we started up, and
130 +     * will thus never have generated a heartbeat - yet
131 +     * will still want to know they're not responding.
132 +     */
133 +    private void createInitialHosts() {
134 +        // get the initial list of hosts from the config
135 +        String initialHosts = "";
136 +        try {
137 +            initialHosts = _cp.getProperty(_name, "Monitor.Heartbeat.initialHosts");
138 +        } catch (PropertyNotFoundException e) {
139 +            // just leave initialHosts empty
140 +            _logger.write(Heartbeat__Monitor.this.toString(), Logger.DEBUG, "No initial list of hosts set, defaulting to none.");
141 +        }
142 +        
143 +        // parse through the initial hosts adding them
144 +        StringTokenizer st = new StringTokenizer(initialHosts, ";");
145 +        while (st.hasMoreTokens()) {
146 +            String source = st.nextToken();
147 +            // check if they already exist, don't want to add them twice
148 +            if (!_hosts.containsKey(source)) {
149 +                synchronized(this) {
150 +                    _hosts.put(source, new HeartbeatHolder(new Register(source, _name)));
151 +                }
152 +            }
153 +            HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source);
154 +            // set a "fake" heartbeat
155 +            lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000);
156 +        }
157 +    }
158  
159   //---ACCESSOR/MUTATOR METHODS---
160      
# Line 229 | Line 268 | public class Heartbeat__Monitor extends MonitorSkeleto
268                      checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod"));
269                  } catch (PropertyNotFoundException e) {
270                      checkPeriod = DEFAULT_CHECK_PERIOD;
271 <                    _logger.write(this.toString(), Logger.WARNING, "Monitor.Heartbeat.checkPeriod value unavailable using default of " + checkPeriod + " seconds");
271 >                    _logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "Monitor.Heartbeat.checkPeriod value unavailable using default of " + checkPeriod + " seconds");
272                  } catch (NumberFormatException e) {
273                      checkPeriod = DEFAULT_CHECK_PERIOD;
274 <                    _logger.write(this.toString(), Logger.WARNING, "Erronous Monitor.Heartbeat.checkPeriod value in configuration using default of " + checkPeriod + " seconds");
274 >                    _logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "Erronous Monitor.Heartbeat.checkPeriod value in configuration using default of " + checkPeriod + " seconds");
275                  }
276                  
277 <                synchronized(this) {
277 >                synchronized(Heartbeat__Monitor.this) {
278                      // perform the checks (use HB hash, although they *should* be the same)
279                      Iterator i = _hosts.keySet().iterator();
280                      while(i.hasNext()) {
# Line 276 | Line 315 | public class Heartbeat__Monitor extends MonitorSkeleto
315                  hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.TCPUpdateTime"));
316              } catch (PropertyNotFoundException e) {
317                  hostHBinterval = 0;
318 <                _logger.write(this.toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds");
318 >                _logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds");
319              } catch (NumberFormatException e) {
320                  hostHBinterval = 0;
321 <                _logger.write(this.toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds");
321 >                _logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds");
322              }
323              
324              // get host's last HB time (seconds)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines