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.23 by tdb, Mon Feb 12 00:45:33 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 >     * Constructs an instance of a FilterThread
39 >     *
40 >     * @param queue the Queue this filter is using
41 >     * @param parent a CORBA reference to our parent filter
42       */
43 <    public FilterThread(DatagramPacket packet, Filter parent){
43 >    public FilterThread(Queue queue, Filter parent){
44          _parent = parent;
45 <        _rawPacket = packet.getData();
46 <        _logger.write(toString(), Logger.DEBUG, "created");
40 <        
45 >        _queue = queue;
46 >        _logger.write(toString(), Logger.SYSINIT, "created");
47      }
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    }
48  
49   //---PUBLIC METHODS---
50  
51      /**
52 <     * Runs the thread
52 >     * Runs the thread, getting data from the Queue and
53 >     * sending it on to the parent filter.
54       */
55      public void run(){
56 <
57 <        // Get a string without any null characters in it.
58 <        //  -- maybe String.trim() would be better here ?
59 <        String xml = new String(_rawPacket);
60 <        if (xml.indexOf(0) != -1) {
61 <            xml = xml.substring(0, xml.indexOf(0));
56 >        // get a queue for ourselves
57 >        int n = _queue.getQueue();
58 >        // keep these out here, saves recreating the object
59 >        String xml = null;
60 >        while(true) {
61 >            // get a String of xml
62 >            try {
63 >                xml = (String) _queue.get(n);
64 >            }
65 >            catch (InvalidQueueException e) {
66 >                _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
67 >            }
68 >            
69 >            // Get a string without any null characters in it.
70 >            //  -- maybe String.trim() would be better here ?
71 >            if (xml.indexOf(0) != -1) {
72 >                xml = xml.substring(0, xml.indexOf(0));
73 >            }
74 >            else {
75 >                xml = xml.substring(0, xml.length());
76 >            }
77 >            
78 >            // Bundle the XML all on one line (saves space and simplifies
79 >            // the protocol between clientinterface and client).
80 >            StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n");
81 >            xml = "";
82 >            while (tokenizer.hasMoreTokens()) {
83 >                xml += tokenizer.nextToken();
84 >            }
85 >            
86 >            // Use XMLPacketMaker to make an XMLPacket object.
87 >            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
88 >            XMLPacket packet = xmlPacketMaker.createXMLPacket();
89 >                  
90 >            if(packet != null) {
91 >                // packet is not null
92 >                // packet was not dropped by a plugin
93 >                // ... best pass it on !
94 >                if(PluginFilterManager.getInstance().runFilters(packet)) {
95 >                    _parent.receiveXML(xml);
96 >                }
97 >                else {
98 >                    // we filtered it
99 >                    _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
100 >                }
101 >            }
102 >            else {
103 >                // we had a null
104 >                _logger.write(toString(), Logger.DEBUG, "An packet containing ill-parsing XML was rejected.");
105 >            }
106          }
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        
107      }
108  
109      /**
# Line 111 | Line 134 | public class FilterThread extends Thread{
134      Filter _parent;
135      
136      /**
137 <     * The raw packet data
137 >     * The Queue object
138       */
139 <    byte[] _rawPacket;
139 >    Queue _queue;
140      
141      /**
142       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines