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.20 by tdb, Tue May 29 17:02:34 2001 UTC vs.
Revision 1.21 by tdb, Mon Nov 26 12:56:33 2001 UTC

# Line 4 | Line 4 | package uk.org.iscream.cms.server.client.monitors;
4   //---IMPORTS---
5   import java.util.HashMap;
6   import java.util.Iterator;
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.*;
# 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 115 | Line 117 | public class Heartbeat__Monitor extends MonitorSkeleto
117              }
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---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines