1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
|
|
22 |
|
//---IMPORTS--- |
27 |
|
|
28 |
|
/** |
29 |
|
* Configurator object for the JavaHost |
30 |
< |
* Will connect to the configurator manager and collect its specific |
30 |
> |
* Will connect to the filter manager and collect its specific |
31 |
|
* configuration |
32 |
|
* |
33 |
|
* @author $Author$ |
71 |
|
myProperties = new HashMap(); |
72 |
|
configChanged = false; |
73 |
|
|
74 |
+ |
// time in seconds before first retry |
75 |
+ |
filterManagerRetryTime = 10; |
76 |
|
|
77 |
|
// do the funky jibble |
78 |
|
connect(serverName, serverPort); |
81 |
|
//---PUBLIC METHODS--- |
82 |
|
|
83 |
|
public InetAddress getFilterName(){ |
84 |
< |
// will return the most recient IP address (if it is dynamic for whatever reason |
84 |
> |
// will return the most recent IP address (if it is dynamic for whatever reason) |
85 |
|
try { |
86 |
|
return InetAddress.getByName(filterName); |
87 |
|
} |
95 |
|
/** |
96 |
|
* Used to retrieve the port to send UDP packets to on the filter |
97 |
|
* |
98 |
< |
* @return an integer corrisponding to the UDP port of the filter |
98 |
> |
* @return an integer corresponding to the UDP port of the filter |
99 |
|
*/ |
100 |
|
public int getFilterUDPPort(){ |
101 |
|
|
105 |
|
/** |
106 |
|
* Used to retrieve the port to send TCP heartbeats to on the filter |
107 |
|
* |
108 |
< |
* @return an integer corrisponding to the TCP of the filter |
108 |
> |
* @return an integer corresponding to the TCP of the filter |
109 |
|
*/ |
110 |
|
public int getFilterTCPPort(){ |
111 |
|
|
137 |
|
Socket mySocket; |
138 |
|
configChanged = false; |
139 |
|
|
140 |
< |
System.out.println("Establishing connection with config manager"); |
140 |
> |
System.out.println("Establishing connection with filter manager"); |
141 |
|
|
142 |
|
// might throw a UnknownHostException |
143 |
|
try { |
150 |
|
// everything is fine |
151 |
|
// sendCommand("LASTMODIFIED"); |
152 |
|
lastModified = sendCommand("LASTMODIFIED"); |
153 |
< |
|
153 |
> |
|
154 |
|
fileList = sendCommand("FILELIST"); |
155 |
+ |
|
156 |
+ |
fQDN = sendCommand("FQDN"); |
157 |
|
// get all the properties |
158 |
|
if ( numProperties > 0 ){ |
159 |
|
// sendCommand("CONFIG"); |
169 |
|
filterName = tok.nextToken(); |
170 |
|
filterUDPPort = Integer.parseInt(tok.nextToken()); |
171 |
|
filterTCPPort = Integer.parseInt(tok.nextToken()); |
172 |
< |
|
172 |
> |
|
173 |
|
sendCommand("END"); |
174 |
|
|
175 |
|
} |
177 |
|
|
178 |
|
// close the socket |
179 |
|
mySocket.close(); |
180 |
< |
System.out.println("Completed communication with config manager"); |
180 |
> |
System.out.println("Completed communication with filter manager"); |
181 |
|
|
182 |
|
} |
183 |
|
catch ( UnknownHostException e ){ |
187 |
|
catch ( IOException e ){ |
188 |
|
// what to do |
189 |
|
System.out.println("Unable to read from socket, might not be open"); |
190 |
+ |
System.out.println("Retrying in "+filterManagerRetryTime+" seconds"); |
191 |
+ |
configChanged = true; |
192 |
+ |
try { |
193 |
+ |
Thread.sleep(filterManagerRetryTime*1000); |
194 |
+ |
} |
195 |
+ |
catch( InterruptedException f ){ |
196 |
+ |
System.out.println("Sleep interrupted"); |
197 |
+ |
} |
198 |
+ |
filterManagerRetryTime = filterManagerRetryTime * 2; |
199 |
+ |
// warning this WILL cause a stack overflow after a while.. |
200 |
+ |
// need to fix it. |
201 |
+ |
connect(serverName, serverPort); |
202 |
|
} |
203 |
|
|
204 |
|
} // connect |
233 |
|
catch ( IOException e ){ |
234 |
|
// what to do |
235 |
|
System.out.println("Unable to read from socket, might not be open"); |
236 |
+ |
System.out.println("Re-establishing contact with filter manager"); |
237 |
+ |
configChanged = true; |
238 |
|
} |
239 |
|
} |
240 |
|
|
266 |
|
private boolean configChanged; |
267 |
|
private String lastModified; |
268 |
|
private String fileList; |
269 |
+ |
private String fQDN; |
270 |
|
private int numProperties; |
271 |
|
private HashMap myProperties; |
272 |
|
private String filterName; |
275 |
|
private ArrayList aList; |
276 |
|
private BufferedReader socketIn; |
277 |
|
private PrintWriter socketOut; |
278 |
+ |
private int filterManagerRetryTime; |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
//---STATIC ATTRIBUTES--- |
283 |
|
|
284 |
< |
} // class |
284 |
> |
} // class |