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.26
Committed: Sat Mar 10 04:03:07 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.25: +5 -4 lines
Log Message:
Changes due to the alterations in the XML creation code. The XMLPacketMaker now
only needs to be created once, and can then be called multiple times to create
XML packets. This should be more efficient in the long run.

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