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.19 by tdb, Mon Mar 26 18:07:11 2001 UTC vs.
Revision 1.24 by tdb, Wed Feb 5 16:43:45 2003 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   //---PACKAGE DECLARATION---
22 < package uk.org.iscream.client.monitors;
22 > package uk.org.iscream.cms.server.client.monitors;
23  
24   //---IMPORTS---
25   import java.util.HashMap;
26   import java.util.Iterator;
27 < import uk.org.iscream.client.*;
28 < import uk.org.iscream.core.*;
29 < import uk.org.iscream.util.*;
30 < import uk.org.iscream.componentmanager.*;
27 > import java.util.StringTokenizer;
28 > import uk.org.iscream.cms.server.client.*;
29 > import uk.org.iscream.cms.server.core.*;
30 > import uk.org.iscream.cms.util.*;
31 > import uk.org.iscream.cms.server.componentmanager.*;
32  
33   /**
34   * This Monitor watches heartbeats.
# Line 51 | Line 72 | public class Heartbeat__Monitor extends MonitorSkeleto
72       */
73      public Heartbeat__Monitor() {
74          super();
75 +        createInitialHosts();
76          new HeartbeatWorker().start();
77      }
78  
# Line 77 | Line 99 | public class Heartbeat__Monitor extends MonitorSkeleto
99       * Overrides the {@link java.lang.Object#toString() Object.toString()}
100       * method to provide clean logging (every class should have this).
101       *
102 <     * This uses the uk.org.iscream.util.NameFormat class
102 >     * This uses the uk.org.iscream.cms.util.NameFormat class
103       * to format the toString()
104       *
105       * @return the name of this class and its CVS revision
# Line 115 | Line 137 | public class Heartbeat__Monitor extends MonitorSkeleto
137              }
138          }
139          return Alert.thresholdNORMAL;
140 +    }
141 +    
142 +    /**
143 +     * Gets an initial list of hosts from the config
144 +     * and adds a fake set of heartbeats for them.
145 +     * If the hosts don't respond within the timeout
146 +     * period an alert will be raised.
147 +     *
148 +     * The effect of this is to allow us to know about
149 +     * hosts which weren't on when we started up, and
150 +     * will thus never have generated a heartbeat - yet
151 +     * will still want to know they're not responding.
152 +     */
153 +    private void createInitialHosts() {
154 +        // get the initial list of hosts from the config
155 +        String initialHosts = "";
156 +        try {
157 +            initialHosts = _cp.getProperty(_name, "Monitor.Heartbeat.initialHosts");
158 +        } catch (PropertyNotFoundException e) {
159 +            // just leave initialHosts empty
160 +            _logger.write(Heartbeat__Monitor.this.toString(), Logger.DEBUG, "No initial list of hosts set, defaulting to none.");
161 +        }
162 +        
163 +        // parse through the initial hosts adding them
164 +        StringTokenizer st = new StringTokenizer(initialHosts, ";");
165 +        while (st.hasMoreTokens()) {
166 +            String source = st.nextToken();
167 +            // check if they already exist, don't want to add them twice
168 +            if (!_hosts.containsKey(source)) {
169 +                synchronized(this) {
170 +                    _hosts.put(source, new HeartbeatHolder(new Register(source, _name)));
171 +                }
172 +            }
173 +            HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source);
174 +            // set a "fake" heartbeat
175 +            lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000);
176 +        }
177      }
178  
179   //---ACCESSOR/MUTATOR METHODS---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines