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. |
52 |
|
*/ |
53 |
|
public Heartbeat__Monitor() { |
54 |
|
super(); |
55 |
+ |
createInitialHosts(); |
56 |
|
new HeartbeatWorker().start(); |
57 |
|
} |
58 |
|
|
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 |
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--- |