14 |
|
* Passes the data through various plugins, then |
15 |
|
* passes it on to the parent filter. |
16 |
|
* |
17 |
+ |
* Now grabs data from a single queue, rather than |
18 |
+ |
* waiting to be contacted. |
19 |
+ |
* |
20 |
|
* @author $Author$ |
21 |
|
* @version $Id$ |
22 |
|
*/ |
32 |
|
//---STATIC METHODS--- |
33 |
|
|
34 |
|
//---CONSTRUCTORS--- |
35 |
< |
|
35 |
> |
|
36 |
|
/** |
37 |
< |
* Class constructor. Obtains the byte[] from a DatagramPacket. |
37 |
> |
* Class constructor. |
38 |
|
*/ |
39 |
< |
public FilterThread(DatagramPacket packet, Filter parent){ |
39 |
> |
public FilterThread(Queue queue, Filter parent){ |
40 |
|
_parent = parent; |
41 |
< |
_rawPacket = packet.getData(); |
41 |
> |
_queue = queue; |
42 |
|
_logger.write(toString(), Logger.DEBUG, "created"); |
40 |
– |
|
43 |
|
} |
42 |
– |
|
43 |
– |
/** |
44 |
– |
* Class constructor for passing XML Strings. |
45 |
– |
*/ |
46 |
– |
public FilterThread(String xml, Filter parent){ |
47 |
– |
_parent = parent; |
48 |
– |
_rawPacket = xml.getBytes(); |
49 |
– |
_logger.write(toString(), Logger.DEBUG, "created"); |
50 |
– |
} |
44 |
|
|
45 |
|
//---PUBLIC METHODS--- |
46 |
|
|
48 |
|
* Runs the thread |
49 |
|
*/ |
50 |
|
public void run(){ |
51 |
< |
|
52 |
< |
// Get a string without any null characters in it. |
53 |
< |
// -- maybe String.trim() would be better here ? |
54 |
< |
String xml = new String(_rawPacket); |
55 |
< |
if (xml.indexOf(0) != -1) { |
56 |
< |
xml = xml.substring(0, xml.indexOf(0)); |
51 |
> |
// get a queue for ourselves |
52 |
> |
int n = _queue.getQueue(); |
53 |
> |
// keep this out here, saves recreating the object |
54 |
> |
String xml = null; |
55 |
> |
while(true) { |
56 |
> |
// get a String of xml |
57 |
> |
try { |
58 |
> |
xml = (String) _queue.get(n); |
59 |
> |
} |
60 |
> |
catch (InvalidQueueException e) { |
61 |
> |
_logger.write(toString(), Logger.ERROR, "Queue error: "+e); |
62 |
> |
} |
63 |
> |
|
64 |
> |
// Get a string without any null characters in it. |
65 |
> |
// -- maybe String.trim() would be better here ? |
66 |
> |
if (xml.indexOf(0) != -1) { |
67 |
> |
xml = xml.substring(0, xml.indexOf(0)); |
68 |
> |
} |
69 |
> |
else { |
70 |
> |
xml = xml.substring(0, xml.length()); |
71 |
> |
} |
72 |
> |
|
73 |
> |
// Use XMLPacketMaker to make an XMLPacket object. |
74 |
> |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
75 |
> |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
76 |
> |
|
77 |
> |
if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { |
78 |
> |
// packet is not null |
79 |
> |
// packet was not dropped by a plugin |
80 |
> |
// ... best pass it on ! |
81 |
> |
_parent.receiveXML(xml); |
82 |
> |
} |
83 |
> |
else { |
84 |
> |
// either we had a null, or a plugin dropped it |
85 |
> |
_logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); |
86 |
> |
} |
87 |
|
} |
65 |
– |
else { |
66 |
– |
xml = xml.substring(0, xml.length()); |
67 |
– |
} |
68 |
– |
|
69 |
– |
// Use my XMLPacketMaker to make an XMLPacket object. |
70 |
– |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
71 |
– |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
72 |
– |
|
73 |
– |
if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { |
74 |
– |
// packet is not null |
75 |
– |
// packet was not dropped by a plugin |
76 |
– |
// ... best pass it on ! |
77 |
– |
_parent.receiveXML(xml); |
78 |
– |
} |
79 |
– |
else { |
80 |
– |
// either we had a null, or a plugin dropped it |
81 |
– |
_logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); |
82 |
– |
} |
83 |
– |
|
88 |
|
} |
89 |
|
|
90 |
|
/** |
115 |
|
Filter _parent; |
116 |
|
|
117 |
|
/** |
118 |
< |
* The raw packet data |
118 |
> |
* The Queue object |
119 |
|
*/ |
120 |
< |
byte[] _rawPacket; |
120 |
> |
Queue _queue; |
121 |
|
|
122 |
|
/** |
123 |
|
* This is the friendly identifier of the |