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.*; |
12 |
|
|
35 |
|
//---CONSTRUCTORS--- |
36 |
|
|
37 |
|
/** |
38 |
< |
* Class constructor. |
38 |
> |
* Constructs an instance of a FilterThread |
39 |
> |
* |
40 |
> |
* @param queue the Queue this filter is using |
41 |
|
*/ |
42 |
< |
public FilterThread(Queue queue, Filter parent){ |
43 |
< |
_parent = parent; |
42 |
> |
public FilterThread(Queue queue){ |
43 |
> |
// set the Thread name |
44 |
> |
setName("filter.FilterThread"); |
45 |
> |
|
46 |
|
_queue = queue; |
47 |
< |
_logger.write(toString(), Logger.DEBUG, "created"); |
47 |
> |
_logger.write(toString(), Logger.SYSINIT, "created"); |
48 |
|
} |
49 |
|
|
50 |
|
//---PUBLIC METHODS--- |
51 |
|
|
52 |
|
/** |
53 |
< |
* Runs the thread |
53 |
> |
* Runs the thread, getting data from the Queue and |
54 |
> |
* sending it on to the parent filter. |
55 |
|
*/ |
56 |
|
public void run(){ |
57 |
+ |
// setup the XMLPacketMaker |
58 |
+ |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
59 |
|
// get a queue for ourselves |
60 |
|
int n = _queue.getQueue(); |
61 |
|
// keep these out here, saves recreating the object |
78 |
|
xml = xml.substring(0, xml.length()); |
79 |
|
} |
80 |
|
|
73 |
– |
|
81 |
|
// Bundle the XML all on one line (saves space and simplifies |
82 |
< |
// the protocol between clientinterface and client. |
82 |
> |
// the protocol between clientinterface and client). |
83 |
|
StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n"); |
84 |
|
xml = ""; |
85 |
|
while (tokenizer.hasMoreTokens()) { |
86 |
|
xml += tokenizer.nextToken(); |
87 |
|
} |
88 |
|
|
82 |
– |
|
89 |
|
// Use XMLPacketMaker to make an XMLPacket object. |
90 |
< |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
91 |
< |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
92 |
< |
|
93 |
< |
if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { |
94 |
< |
// packet is not null |
95 |
< |
// packet was not dropped by a plugin |
96 |
< |
// ... best pass it on ! |
91 |
< |
_parent.receiveXML(xml); |
90 |
> |
XMLPacket packet = null; |
91 |
> |
try { |
92 |
> |
packet = xmlPacketMaker.createXMLPacket(xml); |
93 |
> |
} catch(InvalidXMLException e) { |
94 |
> |
_logger.write(toString(), Logger.ERROR, "Invalid XML: "+e); |
95 |
> |
// skip the rest of this loop iteration |
96 |
> |
continue; |
97 |
|
} |
98 |
+ |
|
99 |
+ |
// get parent |
100 |
+ |
Filter parent; |
101 |
+ |
try { |
102 |
+ |
String parentFilterName = ConfigurationProxy.getInstance().getProperty(FilterMain.NAME, "Filter.parentFilter"); |
103 |
+ |
parent = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
104 |
+ |
} catch (PropertyNotFoundException e) { |
105 |
+ |
continue; |
106 |
+ |
} |
107 |
+ |
|
108 |
+ |
// XMLPacket is ok, run filters... |
109 |
+ |
if(PluginFilterManager.getInstance().runFilters(packet)) { |
110 |
+ |
// and pass it on... |
111 |
+ |
parent.receiveXML(xml); |
112 |
+ |
} |
113 |
|
else { |
114 |
< |
// either we had a null, or a plugin dropped it |
114 |
> |
// ... or filtered it |
115 |
|
_logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); |
116 |
|
} |
117 |
|
} |
138 |
|
//---ACCESSOR/MUTATOR METHODS--- |
139 |
|
|
140 |
|
//---ATTRIBUTES--- |
121 |
– |
|
122 |
– |
/** |
123 |
– |
* Our parent filter |
124 |
– |
*/ |
125 |
– |
Filter _parent; |
141 |
|
|
142 |
|
/** |
143 |
|
* The Queue object |
160 |
|
* system logger that is being used. |
161 |
|
*/ |
162 |
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
163 |
+ |
|
164 |
+ |
/** |
165 |
+ |
* A reference to the reference manager in use |
166 |
+ |
*/ |
167 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
168 |
|
|
169 |
|
//---STATIC ATTRIBUTES--- |
170 |
|
|