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.9 by ajm, Wed Nov 29 21:27:39 2000 UTC vs.
Revision 1.14 by ajm, Wed Dec 13 13:36:46 2000 UTC

# Line 7 | Line 7 | import java.net.*;
7   import java.util.*;
8   import uk.ac.ukc.iscream.core.*;
9   import uk.ac.ukc.iscream.filter.*;
10 < import uk.ac.ukc.iscream.xml.*;
10 > import uk.ac.ukc.iscream.util.*;
11  
12   /**
13 < * Handle an incoming UDP packet as a separate thread.
13 > * Handle an incoming packet as a separate thread.
14 > * Passes the data through various plugins, then
15 > * passes it on to the parent filter.
16   *
17   * @author  $Author$
18   * @version $Id$
# Line 28 | Line 30 | public class FilterThread extends Thread{
30  
31   //---CONSTRUCTORS---
32  
33 <    // Class constructor. Obtains the byte[] from a DatagramPacket.
34 <    public FilterThread(DatagramPacket packet, String name, Filter parent, Logger logger){
35 <        _name = name;
36 <        this.parent = parent;
37 <        this.rawPacket = packet.getData();
38 <        this.logger = logger;
39 <        logger.write(this.toString(), Logger.DEBUG, "created");
33 >    /**
34 >     * Class constructor. Obtains the byte[] from a DatagramPacket.
35 >     */
36 >    public FilterThread(DatagramPacket packet, Filter parent){
37 >        _parent = parent;
38 >        _rawPacket = packet.getData();
39 >        _logger.write(toString(), Logger.DEBUG, "created");
40          
41      }
42      
43 <    // Class constructor for passing XML Strings.
44 <    public FilterThread(String xml, String name, Filter parent, Logger logger){
45 <        _name = name;
46 <        this.logger = logger;
47 <        this.parent = parent;
48 <        this.rawPacket = xml.getBytes();
49 <        logger.write(this.toString(), Logger.DEBUG, "created");
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      }
51  
52   //---PUBLIC METHODS---
53  
54 +    /**
55 +     * Runs the thread
56 +     */
57      public void run(){
58  
59          // Get a string without any null characters in it.
60 <        String xml = new String(rawPacket);
60 >        //  -- maybe String.trim() would be better here ?
61 >        String xml = new String(_rawPacket);
62          if (xml.indexOf(0) != -1) {
63              xml = xml.substring(0, xml.indexOf(0));
64          }
# Line 61 | Line 67 | public class FilterThread extends Thread{
67          }
68          
69          // Use my XMLPacketMaker to make an XMLPacket object.
70 <        XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml, logger);
70 >        XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
71          XMLPacket packet = xmlPacketMaker.createXMLPacket();
72 <        
73 <        logger.write(this.toString(), Logger.DEBUG, "got data, filtering and passing to parent - " + packet.printAll());
74 <        
75 <        if (packet == null){
76 <            // A null XML packet was returned - don't pass it on.
77 <            logger.write(this.toString(), Logger.SYSMSG, "An XML UDP packet was sucessfully filtered from the system.");
72 <            return;
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          
75        // Now do something with this XMLPacket!!!
76        // .... let's try this...
77        parent.receiveXML(xml);
78    
84      }
85  
86      /**
87       * Overrides the {@link java.lang.Object#toString() Object.toString()}
88       * method to provide clean logging (every class should have this).
89       *
90 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
91 +     * to format the toString()
92 +     *
93       * @return the name of this class and its CVS revision
94       */
95      public String toString() {
96 <        return this.getClass().getName() + "{" + _name + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
96 >        return FormatName.getName(
97 >            _name,
98 >            getClass().getName(),
99 >            REVISION);
100      }
101  
102   //---PRIVATE METHODS---
# Line 94 | Line 105 | public class FilterThread extends Thread{
105  
106   //---ATTRIBUTES---
107  
108 <    Filter parent;
109 <    byte[] rawPacket;
110 <    Logger logger;
111 <    String _name;
108 >    /**
109 >     * Our parent filter
110 >     */
111 >    Filter _parent;
112 >    
113 >    /**
114 >     * The raw packet data
115 >     */
116 >    byte[] _rawPacket;
117 >    
118 >    /**
119 >     * This is the friendly identifier of the
120 >     * component this class is running in.
121 >     * eg, a Filter may be called "filter1",
122 >     * If this class does not have an owning
123 >     * component,  a name from the configuration
124 >     * can be placed here.  This name could also
125 >     * be changed to null for utility classes.
126 >     */
127 >    private String _name = FilterMain.NAME;
128 >
129 >    /**
130 >     * This holds a reference to the
131 >     * system logger that is being used.
132 >     */
133 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
134  
135   //---STATIC ATTRIBUTES---
136  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines