35 |
|
* |
36 |
|
* @param listenPort The port that the server will listen on. |
37 |
|
*/ |
38 |
< |
public HostListener(int listenPort) { |
38 |
> |
public HostListener() { |
39 |
|
// set the Thread name |
40 |
|
setName("filtermanager.HostListener"); |
41 |
|
|
42 |
– |
_listenPort = listenPort; |
42 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
43 |
|
} |
44 |
|
|
46 |
– |
|
47 |
– |
|
45 |
|
//---PUBLIC METHODS--- |
46 |
|
|
47 |
|
/** |
56 |
|
// We use this boolean so we can break out of the while loop if we want |
57 |
|
boolean run = true; |
58 |
|
try{ |
59 |
+ |
// Work out the port we want |
60 |
+ |
int listenPort = Integer.parseInt(ConfigurationProxy.getInstance().getProperty("FilterManager", "FilterManager.listenPort")); |
61 |
|
// Setup the ServerSocket so that clients can connect |
62 |
< |
listenSocket = new ServerSocket(_listenPort); |
63 |
< |
} |
65 |
< |
catch(IOException e){ |
66 |
< |
} |
67 |
< |
// Log what machine/port we're listening on |
68 |
< |
try{ |
69 |
< |
_logger.write(toString(), Logger.SYSMSG, "Server listening on " |
62 |
> |
listenSocket = new ServerSocket(listenPort); |
63 |
> |
_logger.write(toString(), Logger.SYSMSG, "Server listening on " |
64 |
|
+InetAddress.getLocalHost().getHostName() |
65 |
|
+"/"+InetAddress.getLocalHost().getHostAddress() |
66 |
|
+" port "+listenSocket.getLocalPort()); |
67 |
< |
} |
68 |
< |
catch(UnknownHostException e){ |
67 |
> |
|
68 |
> |
} |
69 |
> |
catch(UnknownHostException e){ |
70 |
|
_logger.write(toString(), Logger.SYSMSG, "Server listening on UnknownHost " |
71 |
|
+"port "+listenSocket.getLocalPort()); |
72 |
|
} |
73 |
+ |
catch(IOException e){ |
74 |
+ |
_logger.write(toString(), Logger.FATAL, "IO Error, can't start FilterManager :"+e); |
75 |
+ |
run = false; |
76 |
+ |
} |
77 |
+ |
catch(PropertyNotFoundException e){ |
78 |
+ |
_logger.write(toString(), Logger.FATAL, "Fatal Error, can't find config :"+e); |
79 |
+ |
run = false; |
80 |
+ |
} |
81 |
+ |
catch(NumberFormatException e){ |
82 |
+ |
_logger.write(toString(), Logger.FATAL, "Invalid port configuration found :"+e); |
83 |
+ |
run = false; |
84 |
+ |
} |
85 |
+ |
|
86 |
|
// Loop round constantly until we decide to stop |
87 |
|
while(run){ |
88 |
|
Socket hostSocket=null; |
150 |
|
* be changed to null for utility classes. |
151 |
|
*/ |
152 |
|
private String _name = FilterManager.NAME; |
145 |
– |
|
146 |
– |
/** |
147 |
– |
* The port on which the server should listen. |
148 |
– |
*/ |
149 |
– |
private int _listenPort; |
153 |
|
|
154 |
|
//---STATIC ATTRIBUTES--- |
155 |
|
|