--- projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterThread.java 2000/12/13 13:36:46 1.14 +++ projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterThread.java 2001/01/12 00:45:25 1.15 @@ -14,8 +14,11 @@ import uk.ac.ukc.iscream.util.*; * Passes the data through various plugins, then * passes it on to the parent filter. * - * @author $Author: ajm $ - * @version $Id: FilterThread.java,v 1.14 2000/12/13 13:36:46 ajm Exp $ + * Now grabs data from a single queue, rather than + * waiting to be contacted. + * + * @author $Author: tdb $ + * @version $Id: FilterThread.java,v 1.15 2001/01/12 00:45:25 tdb Exp $ */ public class FilterThread extends Thread{ @@ -24,30 +27,20 @@ public class FilterThread extends Thread{ /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.14 $"; + public final String REVISION = "$Revision: 1.15 $"; //---STATIC METHODS--- //---CONSTRUCTORS--- - + /** - * Class constructor. Obtains the byte[] from a DatagramPacket. + * Class constructor. */ - public FilterThread(DatagramPacket packet, Filter parent){ + public FilterThread(Queue queue, Filter parent){ _parent = parent; - _rawPacket = packet.getData(); + _queue = queue; _logger.write(toString(), Logger.DEBUG, "created"); - } - - /** - * Class constructor for passing XML Strings. - */ - public FilterThread(String xml, Filter parent){ - _parent = parent; - _rawPacket = xml.getBytes(); - _logger.write(toString(), Logger.DEBUG, "created"); - } //---PUBLIC METHODS--- @@ -55,32 +48,43 @@ public class FilterThread extends Thread{ * Runs the thread */ public void run(){ - - // Get a string without any null characters in it. - // -- maybe String.trim() would be better here ? - String xml = new String(_rawPacket); - if (xml.indexOf(0) != -1) { - xml = xml.substring(0, xml.indexOf(0)); + // get a queue for ourselves + int n = _queue.getQueue(); + // keep this out here, saves recreating the object + String xml = null; + while(true) { + // get a String of xml + try { + xml = (String) _queue.get(n); + } + catch (InvalidQueueException e) { + _logger.write(toString(), Logger.ERROR, "Queue error: "+e); + } + + // Get a string without any null characters in it. + // -- maybe String.trim() would be better here ? + if (xml.indexOf(0) != -1) { + xml = xml.substring(0, xml.indexOf(0)); + } + else { + xml = xml.substring(0, xml.length()); + } + + // Use XMLPacketMaker to make an XMLPacket object. + XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); + XMLPacket packet = xmlPacketMaker.createXMLPacket(); + + if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { + // packet is not null + // packet was not dropped by a plugin + // ... best pass it on ! + _parent.receiveXML(xml); + } + else { + // either we had a null, or a plugin dropped it + _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); + } } - else { - xml = xml.substring(0, xml.length()); - } - - // Use my XMLPacketMaker to make an XMLPacket object. - XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); - XMLPacket packet = xmlPacketMaker.createXMLPacket(); - - if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { - // packet is not null - // packet was not dropped by a plugin - // ... best pass it on ! - _parent.receiveXML(xml); - } - else { - // either we had a null, or a plugin dropped it - _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); - } - } /** @@ -111,9 +115,9 @@ public class FilterThread extends Thread{ Filter _parent; /** - * The raw packet data + * The Queue object */ - byte[] _rawPacket; + Queue _queue; /** * This is the friendly identifier of the