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.27
Committed: Tue Mar 13 02:19:46 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.26: +5 -2 lines
Log Message:
Given all the classes that extend Thread a name using Thread.setName(). It is
only representative as far as it will tell us which class the Thread is, but
this will go some way to aiding debugging. If time permitted, more effort could
be taken to name each thread according to what it was dealing with.

File Contents

# User Rev Content
1 tdb 1.8 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.filter;
3    
4     //---IMPORTS---
5 pjm2 1.1 import java.io.*;
6     import java.net.*;
7     import java.util.*;
8 pjm2 1.6 import uk.ac.ukc.iscream.core.*;
9 tdb 1.17 import uk.ac.ukc.iscream.componentmanager.*;
10 tdb 1.2 import uk.ac.ukc.iscream.filter.*;
11 ajm 1.11 import uk.ac.ukc.iscream.util.*;
12 pjm2 1.1
13 tdb 1.8 /**
14 ajm 1.14 * Handle an incoming packet as a separate thread.
15     * Passes the data through various plugins, then
16     * passes it on to the parent filter.
17 tdb 1.8 *
18 tdb 1.15 * Now grabs data from a single queue, rather than
19     * waiting to be contacted.
20     *
21 tdb 1.24 * @author $Author: tdb1 $
22 tdb 1.27 * @version $Id: FilterThread.java,v 1.26 2001/03/10 04:03:07 tdb1 Exp $
23 tdb 1.8 */
24 tdb 1.2 public class FilterThread extends Thread{
25 pjm2 1.1
26 tdb 1.8 //---FINAL ATTRIBUTES---
27    
28     /**
29     * The current CVS revision of this class
30     */
31 tdb 1.27 public final String REVISION = "$Revision: 1.26 $";
32 tdb 1.8
33     //---STATIC METHODS---
34    
35     //---CONSTRUCTORS---
36 tdb 1.15
37 ajm 1.14 /**
38 tdb 1.18 * 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 ajm 1.14 */
43 tdb 1.15 public FilterThread(Queue queue, Filter parent){
44 tdb 1.27 // set the Thread name
45     setName("filter.FilterThread");
46    
47 tdb 1.10 _parent = parent;
48 tdb 1.15 _queue = queue;
49 tdb 1.19 _logger.write(toString(), Logger.SYSINIT, "created");
50 pjm2 1.1 }
51 tdb 1.8
52     //---PUBLIC METHODS---
53    
54 ajm 1.14 /**
55 tdb 1.18 * Runs the thread, getting data from the Queue and
56     * sending it on to the parent filter.
57 ajm 1.14 */
58 pjm2 1.1 public void run(){
59 tdb 1.26 // setup the XMLPacketMaker
60     XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
61 tdb 1.15 // get a queue for ourselves
62     int n = _queue.getQueue();
63 pjm2 1.16 // keep these out here, saves recreating the object
64 tdb 1.15 String xml = null;
65     while(true) {
66     // get a String of xml
67     try {
68     xml = (String) _queue.get(n);
69     }
70     catch (InvalidQueueException e) {
71     _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
72     }
73    
74     // Get a string without any null characters in it.
75     // -- maybe String.trim() would be better here ?
76     if (xml.indexOf(0) != -1) {
77     xml = xml.substring(0, xml.indexOf(0));
78     }
79     else {
80     xml = xml.substring(0, xml.length());
81     }
82 pjm2 1.16
83     // Bundle the XML all on one line (saves space and simplifies
84 tdb 1.18 // the protocol between clientinterface and client).
85 pjm2 1.16 StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n");
86     xml = "";
87     while (tokenizer.hasMoreTokens()) {
88     xml += tokenizer.nextToken();
89     }
90 tdb 1.15
91     // Use XMLPacketMaker to make an XMLPacket object.
92 tdb 1.25 XMLPacket packet = null;
93     try {
94 tdb 1.26 packet = xmlPacketMaker.createXMLPacket(xml);
95 tdb 1.25 } catch(InvalidXMLException e) {
96     _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
97     // skip the rest of this loop iteration
98     continue;
99     }
100    
101     // XMLPacket is ok, so run filters...
102     if(PluginFilterManager.getInstance().runFilters(packet)) {
103     // and pass it on...
104     _parent.receiveXML(xml);
105 tdb 1.15 }
106     else {
107 tdb 1.25 // ... or filtered it
108     _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
109 tdb 1.15 }
110 pjm2 1.1 }
111     }
112 tdb 1.8
113     /**
114     * Overrides the {@link java.lang.Object#toString() Object.toString()}
115     * method to provide clean logging (every class should have this).
116     *
117 ajm 1.14 * This uses the uk.ac.ukc.iscream.util.NameFormat class
118     * to format the toString()
119     *
120 tdb 1.8 * @return the name of this class and its CVS revision
121     */
122     public String toString() {
123 ajm 1.14 return FormatName.getName(
124     _name,
125     getClass().getName(),
126     REVISION);
127 tdb 1.8 }
128    
129     //---PRIVATE METHODS---
130    
131     //---ACCESSOR/MUTATOR METHODS---
132    
133     //---ATTRIBUTES---
134    
135 ajm 1.14 /**
136     * Our parent filter
137     */
138 tdb 1.10 Filter _parent;
139 ajm 1.14
140     /**
141 tdb 1.15 * The Queue object
142 ajm 1.14 */
143 tdb 1.15 Queue _queue;
144 ajm 1.14
145     /**
146     * This is the friendly identifier of the
147     * component this class is running in.
148     * eg, a Filter may be called "filter1",
149     * If this class does not have an owning
150     * component, a name from the configuration
151     * can be placed here. This name could also
152     * be changed to null for utility classes.
153     */
154     private String _name = FilterMain.NAME;
155    
156     /**
157     * This holds a reference to the
158     * system logger that is being used.
159     */
160     private Logger _logger = ReferenceManager.getInstance().getLogger();
161 tdb 1.8
162     //---STATIC ATTRIBUTES---
163    
164 pjm2 1.1 }