ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterThread.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterThread.java (file contents):
Revision 1.14 by ajm, Wed Dec 13 13:36:46 2000 UTC vs.
Revision 1.17 by tdb, Thu Jan 18 23:16:21 2001 UTC

# Line 6 | Line 6 | 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.*;
12  
# Line 14 | Line 15 | import uk.ac.ukc.iscream.util.*;
15   * Passes the data through various plugins, then
16   * passes it on to the parent filter.
17   *
18 + * Now grabs data from a single queue, rather than
19 + * waiting to be contacted.
20 + *
21   * @author  $Author$
22   * @version $Id$
23   */
# Line 29 | Line 33 | public class FilterThread extends Thread{
33   //---STATIC METHODS---
34  
35   //---CONSTRUCTORS---
36 <
36 >  
37      /**
38 <     * Class constructor. Obtains the byte[] from a DatagramPacket.
38 >     * Class constructor.
39       */
40 <    public FilterThread(DatagramPacket packet, Filter parent){
40 >    public FilterThread(Queue queue, Filter parent){
41          _parent = parent;
42 <        _rawPacket = packet.getData();
42 >        _queue = queue;
43          _logger.write(toString(), Logger.DEBUG, "created");
40        
44      }
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    }
45  
46   //---PUBLIC METHODS---
47  
# Line 55 | Line 49 | public class FilterThread extends Thread{
49       * Runs the thread
50       */
51      public void run(){
52 <
53 <        // Get a string without any null characters in it.
54 <        //  -- maybe String.trim() would be better here ?
55 <        String xml = new String(_rawPacket);
56 <        if (xml.indexOf(0) != -1) {
57 <            xml = xml.substring(0, xml.indexOf(0));
52 >        // get a queue for ourselves
53 >        int n = _queue.getQueue();
54 >        // keep these out here, saves recreating the object
55 >        String xml = null;
56 >        while(true) {
57 >            // get a String of xml
58 >            try {
59 >                xml = (String) _queue.get(n);
60 >            }
61 >            catch (InvalidQueueException e) {
62 >                _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
63 >            }
64 >            
65 >            // Get a string without any null characters in it.
66 >            //  -- maybe String.trim() would be better here ?
67 >            if (xml.indexOf(0) != -1) {
68 >                xml = xml.substring(0, xml.indexOf(0));
69 >            }
70 >            else {
71 >                xml = xml.substring(0, xml.length());
72 >            }
73 >            
74 >            
75 >            // Bundle the XML all on one line (saves space and simplifies
76 >            // the protocol between clientinterface and client.
77 >            StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n");
78 >            xml = "";
79 >            while (tokenizer.hasMoreTokens()) {
80 >                xml += tokenizer.nextToken();
81 >            }
82 >            
83 >            
84 >            // Use XMLPacketMaker to make an XMLPacket object.
85 >            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
86 >            XMLPacket packet = xmlPacketMaker.createXMLPacket();
87 >                  
88 >            if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) {
89 >                // packet is not null
90 >                // packet was not dropped by a plugin
91 >                // ... best pass it on !
92 >                _parent.receiveXML(xml);
93 >            }
94 >            else {
95 >                // either we had a null, or a plugin dropped it
96 >                _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
97 >            }
98          }
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        
99      }
100  
101      /**
# Line 111 | Line 126 | public class FilterThread extends Thread{
126      Filter _parent;
127      
128      /**
129 <     * The raw packet data
129 >     * The Queue object
130       */
131 <    byte[] _rawPacket;
131 >    Queue _queue;
132      
133      /**
134       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines