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.1 by pjm2, Wed Nov 22 08:40:53 2000 UTC vs.
Revision 1.13 by tdb, Wed Dec 6 22:57:45 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 < public class UDPReaderThread extends Thread{
12 > /**
13 > * Handle an incoming UDP packet as a separate thread.
14 > *
15 > * @author  $Author$
16 > * @version $Id$
17 > */
18 > public class FilterThread extends Thread{
19  
20 <    public FilterThread(){
21 <        // no-args constructor.
22 <    }
20 > //---FINAL ATTRIBUTES---
21 >
22 >    /**
23 >     * The current CVS revision of this class
24 >     */
25 >    public final String REVISION = "$Revision$";
26      
27 <    public void run(DatagramPacket packet){
28 <        rawPacket = packet.getData();
29 <        start();
27 > //---STATIC METHODS---
28 >
29 > //---CONSTRUCTORS---
30 >
31 >    // Class constructor. Obtains the byte[] from a DatagramPacket.
32 >    public FilterThread(DatagramPacket packet, Filter parent){
33 >        _parent = parent;
34 >        _rawPacket = packet.getData();
35 >        _logger.write(this.toString(), Logger.DEBUG, "created");
36 >        
37      }
38      
39 <    public void run(String xml){
40 <        rawPacket = xml.getBytes();
41 <        start();
39 >    // Class constructor for passing XML Strings.
40 >    public FilterThread(String xml, Filter parent){
41 >        _parent = parent;
42 >        _rawPacket = xml.getBytes();
43 >        _logger.write(this.toString(), Logger.DEBUG, "created");
44      }
45 <    
45 >
46 > //---PUBLIC METHODS---
47 >
48      public void run(){
49  
50          // Get a string without any null characters in it.
51 <        String xml = new String(rawPacket);
52 <        xml = xml.substring(0, xml.indexOf(0));
53 <
54 <        // USe my XMLPacketMaker to make an XMLPacket object.
51 >        //  -- maybe String.trim() would be better here ?
52 >        String xml = new String(_rawPacket);
53 >        if (xml.indexOf(0) != -1) {
54 >            xml = xml.substring(0, xml.indexOf(0));
55 >        }
56 >        else {
57 >            xml = xml.substring(0, xml.length());
58 >        }
59 >        
60 >        // Use my XMLPacketMaker to make an XMLPacket object.
61          XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
62          XMLPacket packet = xmlPacketMaker.createXMLPacket();
63 <
64 <        if (packet == null){
65 <            System.out.println("UDPReaderThread - A null XMLPacket was returned, I think I'll ignore it!");
66 <            return;
63 >              
64 >        if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) {
65 >            // packet is not null
66 >            // packet was not dropped by a plugin
67 >            // ... best pass it on !
68 >            _parent.receiveXML(xml);
69          }
70 <        System.out.println("UDPReaderThread - An XML Packet was read sucessfully: -");
71 <        packet.printAll();
72 <        // Now do something with this XMLPacket!!!
73 <        // .... but what? ;-)
74 <    
70 >        else {
71 >            // either we had a null, or a plugin dropped it
72 >            _logger.write(this.toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
73 >        }
74 >        
75      }
76 <    
77 <    byte[] rawPacket;
76 >
77 >    /**
78 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
79 >     * method to provide clean logging (every class should have this).
80 >     *
81 >     * @return the name of this class and its CVS revision
82 >     */
83 >    public String toString() {
84 >        return this.getClass().getName() + "{" + _name + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
85 >    }
86 >
87 > //---PRIVATE METHODS---
88 >
89 > //---ACCESSOR/MUTATOR METHODS---
90 >
91 > //---ATTRIBUTES---
92 >
93 >    Filter _parent;
94 >    byte[] _rawPacket;
95 >    Logger _logger = ReferenceManager.getInstance().getLogger();
96 >    String _name = ReferenceManager.getInstance().getName();
97 >
98 > //---STATIC ATTRIBUTES---
99 >
100   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines