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--- |
28 |
|
|
29 |
|
/** |
30 |
|
* Configurator object for the JavaHost |
31 |
< |
* Will connect to the configurator manager and collect its specific |
31 |
> |
* Will connect to the filter manager and collect its specific |
32 |
|
* configuration |
33 |
|
* |
34 |
|
* @author $Author$ |
72 |
|
myProperties = new HashMap(); |
73 |
|
configChanged = false; |
74 |
|
|
75 |
+ |
// time in seconds before first retry |
76 |
+ |
filterManagerRetryTime = 10; |
77 |
|
|
78 |
|
// do the funky jibble |
79 |
|
connect(serverName, serverPort); |
82 |
|
//---PUBLIC METHODS--- |
83 |
|
|
84 |
|
public InetAddress getFilterName(){ |
85 |
< |
// will return the most recient IP address (if it is dynamic for whatever reason |
85 |
> |
// will return the most recent IP address (if it is dynamic for whatever reason) |
86 |
|
try { |
87 |
|
return InetAddress.getByName(filterName); |
88 |
|
} |
96 |
|
/** |
97 |
|
* Used to retrieve the port to send UDP packets to on the filter |
98 |
|
* |
99 |
< |
* @return an integer corrisponding to the UDP port of the filter |
99 |
> |
* @return an integer corresponding to the UDP port of the filter |
100 |
|
*/ |
101 |
|
public int getFilterUDPPort(){ |
102 |
|
|
106 |
|
/** |
107 |
|
* Used to retrieve the port to send TCP heartbeats to on the filter |
108 |
|
* |
109 |
< |
* @return an integer corrisponding to the TCP of the filter |
109 |
> |
* @return an integer corresponding to the TCP of the filter |
110 |
|
*/ |
111 |
|
public int getFilterTCPPort(){ |
112 |
|
|
138 |
|
Socket mySocket; |
139 |
|
configChanged = false; |
140 |
|
|
141 |
< |
System.out.println("Establishing connection with config manager"); |
141 |
> |
System.out.println("Establishing connection with filter manager"); |
142 |
|
|
143 |
|
// might throw a UnknownHostException |
144 |
|
try { |
151 |
|
// everything is fine |
152 |
|
// sendCommand("LASTMODIFIED"); |
153 |
|
lastModified = sendCommand("LASTMODIFIED"); |
154 |
< |
|
154 |
> |
|
155 |
|
fileList = sendCommand("FILELIST"); |
156 |
+ |
|
157 |
+ |
fQDN = sendCommand("FQDN"); |
158 |
|
// get all the properties |
159 |
|
if ( numProperties > 0 ){ |
160 |
|
// sendCommand("CONFIG"); |
170 |
|
filterName = tok.nextToken(); |
171 |
|
filterUDPPort = Integer.parseInt(tok.nextToken()); |
172 |
|
filterTCPPort = Integer.parseInt(tok.nextToken()); |
173 |
< |
|
173 |
> |
|
174 |
|
sendCommand("END"); |
175 |
|
|
176 |
|
} |
178 |
|
|
179 |
|
// close the socket |
180 |
|
mySocket.close(); |
181 |
< |
System.out.println("Completed communication with config manager"); |
181 |
> |
System.out.println("Completed communication with filter manager"); |
182 |
|
|
183 |
|
} |
184 |
|
catch ( UnknownHostException e ){ |
188 |
|
catch ( IOException e ){ |
189 |
|
// what to do |
190 |
|
System.out.println("Unable to read from socket, might not be open"); |
191 |
+ |
System.out.println("Retrying in "+filterManagerRetryTime+" seconds"); |
192 |
+ |
configChanged = true; |
193 |
+ |
try { |
194 |
+ |
Thread.sleep(filterManagerRetryTime*1000); |
195 |
+ |
} |
196 |
+ |
catch( InterruptedException f ){ |
197 |
+ |
System.out.println("Sleep interrupted"); |
198 |
+ |
} |
199 |
+ |
filterManagerRetryTime = filterManagerRetryTime * 2; |
200 |
+ |
// warning this WILL cause a stack overflow after a while.. |
201 |
+ |
// need to fix it. |
202 |
+ |
connect(serverName, serverPort); |
203 |
|
} |
204 |
|
|
205 |
|
} // connect |
234 |
|
catch ( IOException e ){ |
235 |
|
// what to do |
236 |
|
System.out.println("Unable to read from socket, might not be open"); |
237 |
+ |
System.out.println("Re-establishing contact with filter manager"); |
238 |
+ |
configChanged = true; |
239 |
|
} |
240 |
|
} |
241 |
|
|
267 |
|
private boolean configChanged; |
268 |
|
private String lastModified; |
269 |
|
private String fileList; |
270 |
+ |
private String fQDN; |
271 |
|
private int numProperties; |
272 |
|
private HashMap myProperties; |
273 |
|
private String filterName; |
276 |
|
private ArrayList aList; |
277 |
|
private BufferedReader socketIn; |
278 |
|
private PrintWriter socketOut; |
279 |
+ |
private int filterManagerRetryTime; |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
//---STATIC ATTRIBUTES--- |
284 |
|
|
285 |
< |
} // class |
285 |
> |
} // class |