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.6 by pjm2, Thu Nov 23 09:36:07 2000 UTC vs.
Revision 1.14 by ajm, Wed Dec 13 13:36:46 2000 UTC

# Line 1 | Line 1
1 + //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.filter;
3 +
4 + //---IMPORTS---
5   import java.io.*;
6   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.util.*;
11  
12 < // Handle an incoming UDP packet as a separate thread.
12 > /**
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$
19 > */
20   public class FilterThread extends Thread{
21  
22 <    // Class constructor. Obtains the byte[] from a DatagramPacket.
23 <    public FilterThread(DatagramPacket packet, Filter parent, Logger logger){
24 <        this.parent = parent;
25 <        this.rawPacket = packet.getData();
26 <        this.logger = logger;
27 <    }
22 > //---FINAL ATTRIBUTES---
23 >
24 >    /**
25 >     * The current CVS revision of this class
26 >     */
27 >    public final String REVISION = "$Revision$";
28      
29 <    // Class constructor for passing XML Strings.
30 <    public FilterThread(String xml, Filter parent, Logger logger){
31 <        this.parent = parent;
32 <        this.rawPacket = xml.getBytes();
29 > //---STATIC METHODS---
30 >
31 > //---CONSTRUCTORS---
32 >
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 +    /**
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          }
65          else {
66              xml = xml.substring(0, xml.length());
67          }
68 <        System.out.println(xml);
34 <
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 <        if (packet == null){
74 <            // A null XML packet was returned - don't pass it on.
75 <            logger.write(this.toString(), Logger.SYSMSG, "An XML UDP packet was sucessfully filtered from the system.");
76 <            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          
45        // Now do something with this XMLPacket!!!
46        // .... let's try this...
47        parent.receiveXML(xml);
48    
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 FormatName.getName(
97 +            _name,
98 +            getClass().getName(),
99 +            REVISION);
100 +    }
101 +
102 + //---PRIVATE METHODS---
103 +
104 + //---ACCESSOR/MUTATOR METHODS---
105 +
106 + //---ATTRIBUTES---
107 +
108 +    /**
109 +     * Our parent filter
110 +     */
111 +    Filter _parent;
112      
113 <    Filter parent;
114 <    byte[] rawPacket;
115 <    Logger logger;
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 >
137   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines