15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
17 |
|
*/ |
18 |
< |
public class Heartbeat__Monitor extends Thread implements PluginMonitor { |
18 |
> |
public class Heartbeat__Monitor implements PluginMonitor, Runnable { |
19 |
|
|
20 |
|
//---FINAL ATTRIBUTES--- |
21 |
|
|
26 |
|
|
27 |
|
public final String DESC = "Monitors Heartbeats."; |
28 |
|
|
29 |
+ |
public final int DEFAULT_CHECK_PERIOD = 60; |
30 |
+ |
|
31 |
|
//---STATIC METHODS--- |
32 |
|
|
33 |
|
//---CONSTRUCTORS--- |
34 |
|
|
35 |
|
public Heartbeat__Monitor() { |
36 |
< |
this.start(); |
36 |
> |
new Thread(this).start(); |
37 |
|
} |
38 |
|
|
39 |
|
//---PUBLIC METHODS--- |
41 |
|
public void run() { |
42 |
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
43 |
|
while(true) { |
44 |
< |
// this cycle period could be done better, maybe ? |
45 |
< |
int checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod")); |
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 |
|
|
56 |
|
// perform the checks (use HB hash, although they *should* be the same) |
57 |
|
Iterator i = _hostsHB.keySet().iterator(); |
73 |
|
Register reg = (Register) _hostsReg.get(source); |
74 |
|
|
75 |
|
// get host's HB interval (seconds) |
76 |
< |
// this should always exist |
66 |
< |
String HBint = cp.getProperty("Host."+source, "TCPUpdateTime"); |
76 |
> |
// this should always exist, thus we set to 0 |
77 |
|
int hostHBinterval = 0; |
78 |
< |
if(HBint != null) { |
78 |
> |
try { |
79 |
|
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "TCPUpdateTime")); |
80 |
< |
} |
81 |
< |
else { |
82 |
< |
hostHBinterval = 60; |
80 |
> |
} catch (PropertyNotFoundException e) { |
81 |
> |
hostHBinterval = 0; |
82 |
> |
_logger.write(toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
83 |
> |
} catch (NumberFormatException e) { |
84 |
> |
hostHBinterval = 0; |
85 |
> |
_logger.write(toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
86 |
|
} |
87 |
|
|
88 |
|
// get host's last HB time (seconds) |