1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.filtermanager; |
2 |
> |
package uk.org.iscream.cms.server.filtermanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
6 |
< |
import uk.ac.ukc.iscream.filter.*; |
7 |
< |
import uk.ac.ukc.iscream.util.*; |
5 |
> |
import uk.org.iscream.cms.server.core.*; |
6 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
7 |
> |
import uk.org.iscream.cms.server.filter.*; |
8 |
> |
import uk.org.iscream.cms.server.util.*; |
9 |
|
import java.net.*; |
10 |
|
import java.io.*; |
11 |
|
|
35 |
|
* |
36 |
|
* @param listenPort The port that the server will listen on. |
37 |
|
*/ |
38 |
< |
public HostListener(int listenPort) { |
39 |
< |
_listenPort = listenPort; |
38 |
> |
public HostListener() { |
39 |
> |
// set the Thread name |
40 |
> |
setName("filtermanager.HostListener"); |
41 |
> |
|
42 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
43 |
|
} |
44 |
|
|
42 |
– |
|
43 |
– |
|
45 |
|
//---PUBLIC METHODS--- |
46 |
|
|
47 |
|
/** |
52 |
|
* and then passing them off to other processes to deal with. |
53 |
|
*/ |
54 |
|
public void run(){ |
55 |
+ |
// setup an empty ACL defaulting to ALLOW |
56 |
+ |
ACL acl = new ACL(ACL.ALLOW); |
57 |
+ |
|
58 |
|
ServerSocket listenSocket=null; |
59 |
|
// We use this boolean so we can break out of the while loop if we want |
60 |
|
boolean run = true; |
61 |
|
try{ |
62 |
+ |
// Work out the port we want |
63 |
+ |
int listenPort = Integer.parseInt(ConfigurationProxy.getInstance().getProperty("FilterManager." + FilterManager.NAME, "FilterManager.listenPort")); |
64 |
|
// Setup the ServerSocket so that clients can connect |
65 |
< |
listenSocket = new ServerSocket(_listenPort); |
66 |
< |
} |
61 |
< |
catch(IOException e){ |
62 |
< |
} |
63 |
< |
// Log what machine/port we're listening on |
64 |
< |
try{ |
65 |
< |
_logger.write(toString(), Logger.SYSMSG, "Server listening on " |
65 |
> |
listenSocket = new ACLServerSocket(acl, listenPort); |
66 |
> |
_logger.write(toString(), Logger.SYSMSG, "Server listening on " |
67 |
|
+InetAddress.getLocalHost().getHostName() |
68 |
|
+"/"+InetAddress.getLocalHost().getHostAddress() |
69 |
|
+" port "+listenSocket.getLocalPort()); |
70 |
< |
} |
71 |
< |
catch(UnknownHostException e){ |
70 |
> |
|
71 |
> |
} |
72 |
> |
catch(UnknownHostException e){ |
73 |
|
_logger.write(toString(), Logger.SYSMSG, "Server listening on UnknownHost " |
74 |
|
+"port "+listenSocket.getLocalPort()); |
75 |
|
} |
76 |
+ |
catch(IOException e){ |
77 |
+ |
_logger.write(toString(), Logger.FATAL, "IO Error, can't start FilterManager :"+e); |
78 |
+ |
run = false; |
79 |
+ |
} |
80 |
+ |
catch(PropertyNotFoundException e){ |
81 |
+ |
_logger.write(toString(), Logger.FATAL, "Fatal Error, can't find config :"+e); |
82 |
+ |
run = false; |
83 |
+ |
} |
84 |
+ |
catch(NumberFormatException e){ |
85 |
+ |
_logger.write(toString(), Logger.FATAL, "Invalid port configuration found :"+e); |
86 |
+ |
run = false; |
87 |
+ |
} |
88 |
+ |
|
89 |
|
// Loop round constantly until we decide to stop |
90 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
91 |
+ |
String stringACL = ""; |
92 |
+ |
String newStringACL = ""; |
93 |
|
while(run){ |
94 |
+ |
// get hold of the ACL in the configuration |
95 |
+ |
try { |
96 |
+ |
newStringACL = cp.getProperty("FilterManager." + FilterManager.NAME, "FilterManager.ACL"); |
97 |
+ |
} |
98 |
+ |
catch(PropertyNotFoundException e) { |
99 |
+ |
// if we can't find it, we'll just use a null ACL |
100 |
+ |
newStringACL = ""; |
101 |
+ |
_logger.write(toString(), Logger.WARNING, "No ACL found for FilterManager, using empty ACL instead: " + e); |
102 |
+ |
} |
103 |
+ |
// check to see if the ACL has changed |
104 |
+ |
if(!newStringACL.equals(stringACL)) { |
105 |
+ |
_logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List"); |
106 |
+ |
// clear the ACL |
107 |
+ |
acl.clear(); |
108 |
+ |
// set the default to something sane |
109 |
+ |
acl.setDefaultMode(ACL.ALLOW); |
110 |
+ |
// add the new ACL (this may change the default) |
111 |
+ |
acl.add(newStringACL); |
112 |
+ |
stringACL = newStringACL; |
113 |
+ |
} |
114 |
|
Socket hostSocket=null; |
115 |
|
try{ |
116 |
|
_logger.write(toString(), Logger.SYSMSG, "Waiting for Connection"); |
142 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
143 |
|
* method to provide clean logging (every class should have this). |
144 |
|
* |
145 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
145 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
146 |
|
* to format the toString() |
147 |
|
* |
148 |
|
* @return the name of this class and its CVS revision |
176 |
|
* be changed to null for utility classes. |
177 |
|
*/ |
178 |
|
private String _name = FilterManager.NAME; |
141 |
– |
|
142 |
– |
/** |
143 |
– |
* The port on which the server should listen. |
144 |
– |
*/ |
145 |
– |
private int _listenPort; |
179 |
|
|
180 |
|
//---STATIC ATTRIBUTES--- |
181 |
|
|