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 |
|
|
23 |
|
//---IMPORTS--- |
55 |
|
System.out.println("Creating System Monitor"); |
56 |
|
SystemMonitor sysMon = new SystemMonitor(config); |
57 |
|
|
58 |
+ |
try { |
59 |
+ |
udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; |
60 |
+ |
System.out.println("Configured UDPUpdateTime"); |
61 |
+ |
} |
62 |
+ |
catch ( NumberFormatException e ){ |
63 |
+ |
System.out.println("The value for UDPUpdateTime is invalid, using a default"); |
64 |
+ |
// 1 mins |
65 |
+ |
udpcheckInterval = 1000 * 60; // 1 minute |
66 |
+ |
} |
67 |
+ |
|
68 |
+ |
try { |
69 |
+ |
tcpcheckInterval = Long.parseLong(config.getProperty("TCPUpdateTime")) * 1000; |
70 |
+ |
System.out.println("Configured TCPUpdateTime"); |
71 |
+ |
} |
72 |
+ |
catch ( NumberFormatException e ){ |
73 |
+ |
System.out.println("The value for UDPUpdateTime is invalid, using a default"); |
74 |
+ |
// 10 mins |
75 |
+ |
tcpcheckInterval = 10000 * 60; // 5 minutes |
76 |
+ |
} |
77 |
+ |
|
78 |
+ |
// the current time.. |
79 |
+ |
long currentTime = System.currentTimeMillis(); |
80 |
+ |
long nextUDP = currentTime + udpcheckInterval; |
81 |
+ |
long nextTCP = currentTime + tcpcheckInterval; |
82 |
+ |
|
83 |
|
while ( true ){ |
84 |
+ |
currentTime = System.currentTimeMillis(); |
85 |
|
// keep going for ever and ever ;) |
86 |
< |
// send a udp packet to the filter declared in config |
87 |
< |
// send it the xml packet created by getInfo() |
88 |
< |
System.out.println("Sending UDP Packet"); |
89 |
< |
LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); |
90 |
< |
config.sendHeartBeat(); |
91 |
< |
if ( config.reloadConfig() ){ |
92 |
< |
System.out.println("Resarting System"); |
93 |
< |
break; |
86 |
> |
|
87 |
> |
if ( nextTCP < nextUDP ){ |
88 |
> |
try { |
89 |
> |
long sleeptime = nextTCP - currentTime; |
90 |
> |
if ( sleeptime > 0 ){ |
91 |
> |
Thread.sleep(sleeptime); |
92 |
> |
} |
93 |
> |
nextTCP += tcpcheckInterval; |
94 |
> |
// send a heartbeat |
95 |
> |
//System.out.println("Sending Heartbeat"); |
96 |
> |
System.out.print("+"); |
97 |
> |
config.sendHeartBeat(); |
98 |
> |
if ( config.reloadConfig() ){ |
99 |
> |
System.out.println("\nRestarting System"); |
100 |
> |
break; |
101 |
> |
} |
102 |
> |
} |
103 |
> |
catch ( InterruptedException e ){ |
104 |
> |
// do nothing |
105 |
> |
} |
106 |
|
} |
107 |
+ |
else { |
108 |
+ |
try { |
109 |
+ |
long sleeptime = nextUDP - currentTime; |
110 |
+ |
if ( sleeptime > 0 ){ |
111 |
+ |
Thread.sleep(sleeptime); |
112 |
+ |
} |
113 |
+ |
nextUDP += udpcheckInterval; |
114 |
+ |
// send a heartbeat |
115 |
+ |
//System.out.println("Sending UDP Packet"); |
116 |
+ |
System.out.print("."); |
117 |
+ |
LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); |
118 |
+ |
|
119 |
+ |
} |
120 |
+ |
catch ( InterruptedException e ){ |
121 |
+ |
// do nothing |
122 |
+ |
} |
123 |
+ |
} |
124 |
+ |
|
125 |
+ |
|
126 |
+ |
|
127 |
|
} // while |
128 |
|
|
129 |
|
|
137 |
|
//---ACCESSOR/MUTATOR METHODS--- |
138 |
|
|
139 |
|
//---ATTRIBUTES--- |
140 |
+ |
|
141 |
+ |
private long udpcheckInterval; |
142 |
+ |
private long tcpcheckInterval; |
143 |
+ |
private final long defaultUpdateTime = 60000; |
144 |
+ |
|
145 |
|
|
146 |
|
//---STATIC ATTRIBUTES--- |
147 |
|
|
148 |
< |
} // class |
148 |
> |
} // class |