1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.filter; |
2 |
> |
package uk.org.iscream.cms.server.filter; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.io.*; |
6 |
|
import java.net.*; |
7 |
|
import java.util.*; |
8 |
< |
import uk.ac.ukc.iscream.core.*; |
9 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
10 |
< |
import uk.ac.ukc.iscream.filter.*; |
11 |
< |
import uk.ac.ukc.iscream.util.*; |
8 |
> |
import uk.org.iscream.cms.server.core.*; |
9 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
10 |
> |
import uk.org.iscream.cms.server.filter.*; |
11 |
> |
import uk.org.iscream.cms.server.util.*; |
12 |
|
|
13 |
|
/** |
14 |
|
* This class contains the main method to be run by |
25 |
|
* The current CVS revision of this class |
26 |
|
*/ |
27 |
|
public final String REVISION = "$Revision$"; |
28 |
< |
|
28 |
> |
|
29 |
|
/** |
30 |
|
* The maximum size of a packet |
31 |
|
*/ |
42 |
|
* @param queue The queue which we are using |
43 |
|
*/ |
44 |
|
public UDPReader(int port, Queue queue){ |
45 |
+ |
// set the Thread name |
46 |
+ |
setName("filter.UDPReader"); |
47 |
+ |
|
48 |
|
_port = port; |
49 |
|
_queue = queue; |
50 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started"); |
51 |
|
} |
52 |
|
|
53 |
|
//---PUBLIC METHODS--- |
57 |
|
* over UDP. |
58 |
|
*/ |
59 |
|
public void run() { |
60 |
+ |
// get our ACL from the configuration |
61 |
+ |
ACL acl = null; |
62 |
+ |
try { |
63 |
+ |
String stringACL = ConfigurationProxy.getInstance().getProperty(FilterMain.NAME, "Filter.UDPACL"); |
64 |
+ |
acl = new ACL(stringACL); |
65 |
+ |
} |
66 |
+ |
catch(PropertyNotFoundException e) { |
67 |
+ |
_logger.write(toString(), Logger.WARNING, "No ACL found for UDPReader: " + e); |
68 |
+ |
} |
69 |
|
|
70 |
|
// setup a Datagram socket |
71 |
|
DatagramSocket socket = null; |
72 |
|
try { |
73 |
< |
socket = new DatagramSocket(_port); |
73 |
> |
// use an ACLServerSocket if we have an ACL |
74 |
> |
if(acl != null) { |
75 |
> |
socket = new ACLDatagramSocket(acl, _port); |
76 |
> |
} |
77 |
> |
else { |
78 |
> |
socket = new DatagramSocket(_port); |
79 |
> |
} |
80 |
|
} |
81 |
|
catch (BindException e){ |
82 |
|
_logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+" as this port was already in use."); |
88 |
|
} |
89 |
|
|
90 |
|
_logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+_port); |
91 |
< |
|
91 |
> |
|
92 |
|
byte[] buf; |
93 |
|
|
94 |
|
// read UDP packets and queue them |
95 |
|
boolean running = true; |
96 |
|
while (running){ |
97 |
|
try { |
98 |
< |
|
99 |
< |
// receive request and put it in the Queue |
98 |
> |
|
99 |
> |
// receive request and put it in the Queue |
100 |
|
buf = new byte[packetSizeLimit]; |
101 |
|
DatagramPacket packet = new DatagramPacket(buf, buf.length); |
102 |
|
socket.receive(packet); |
110 |
|
} |
111 |
|
socket.close(); |
112 |
|
} |
113 |
< |
|
113 |
> |
|
114 |
|
/** |
115 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
116 |
|
* method to provide clean logging (every class should have this). |
117 |
|
* |
118 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
118 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
119 |
|
* to format the toString() |
120 |
|
* |
121 |
|
* @return the name of this class and its CVS revision |
143 |
|
* be changed to null for utility classes. |
144 |
|
*/ |
145 |
|
private String _name = FilterMain.NAME; |
146 |
< |
|
146 |
> |
|
147 |
|
/** |
148 |
|
* This holds a reference to the |
149 |
|
* system logger that is being used. |
158 |
|
/** |
159 |
|
* The Queue object |
160 |
|
*/ |
161 |
< |
Queue _queue; |
161 |
> |
Queue _queue; |
162 |
|
|
163 |
|
//---STATIC ATTRIBUTES--- |
164 |
|
|