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
Revision: 1.10
Committed: Thu Nov 30 02:00:54 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.9: +22 -24 lines
Log Message:
Changed all classes so that references to the Logger and ConfigurationManager
are no longer passed around between classes. All of the classes now utilise
the new ReferenceManager, which makes life much easier.
Also tidied everything so that they all use the same conventions for attributes,
namely the _ prefix to the name.

File Contents

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