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.29
Committed: Wed Mar 14 23:25:29 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.28: +8 -8 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

File Contents

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