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.34
Committed: Fri Mar 22 16:42:54 2002 UTC (22 years, 1 month ago) by tdb
Branch: MAIN
Changes since 1.33: +2 -5 lines
Log Message:
I wonder how much cpu time this "null" statement has wasted?

File Contents

# User Rev Content
1 tdb 1.8 //---PACKAGE DECLARATION---
2 tdb 1.32 package uk.org.iscream.cms.server.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.32 import uk.org.iscream.cms.server.core.*;
9     import uk.org.iscream.cms.server.componentmanager.*;
10     import uk.org.iscream.cms.server.filter.*;
11     import uk.org.iscream.cms.server.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.33 * @author $Author: tdb $
22 tdb 1.34 * @version $Id: FilterThread.java,v 1.33 2002/03/20 13:05:49 tdb 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.34 public final String REVISION = "$Revision: 1.33 $";
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 tdb 1.30 String parentFilterName = "";
64     Filter parent = null;
65 tdb 1.15 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 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 tdb 1.28
98     // get parent
99     try {
100 tdb 1.33 String newParent = ConfigurationProxy.getInstance().getProperty("Filter." + FilterMain.NAME, "Filter.parentFilter");
101 tdb 1.30 if(!parentFilterName.equals(newParent)) {
102 tdb 1.31 parentFilterName = newParent;
103 tdb 1.30 parent = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName));
104     _logger.write(toString(), Logger.DEBUG, "Parent filter changed to: "+parentFilterName);
105     }
106 tdb 1.28 } catch (PropertyNotFoundException e) {
107     continue;
108     }
109    
110     // XMLPacket is ok, run filters...
111 tdb 1.25 if(PluginFilterManager.getInstance().runFilters(packet)) {
112     // and pass it on...
113 tdb 1.28 parent.receiveXML(xml);
114 tdb 1.15 }
115     else {
116 tdb 1.25 // ... or filtered it
117     _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
118 tdb 1.15 }
119 pjm2 1.1 }
120     }
121 tdb 1.8
122     /**
123     * Overrides the {@link java.lang.Object#toString() Object.toString()}
124     * method to provide clean logging (every class should have this).
125     *
126 tdb 1.32 * This uses the uk.org.iscream.cms.server.util.NameFormat class
127 ajm 1.14 * to format the toString()
128     *
129 tdb 1.8 * @return the name of this class and its CVS revision
130     */
131     public String toString() {
132 ajm 1.14 return FormatName.getName(
133     _name,
134     getClass().getName(),
135     REVISION);
136 tdb 1.8 }
137    
138     //---PRIVATE METHODS---
139    
140     //---ACCESSOR/MUTATOR METHODS---
141    
142     //---ATTRIBUTES---
143 ajm 1.14
144     /**
145 tdb 1.15 * The Queue object
146 ajm 1.14 */
147 tdb 1.15 Queue _queue;
148 ajm 1.14
149     /**
150     * This is the friendly identifier of the
151     * component this class is running in.
152     * eg, a Filter may be called "filter1",
153     * If this class does not have an owning
154     * component, a name from the configuration
155     * can be placed here. This name could also
156     * be changed to null for utility classes.
157     */
158     private String _name = FilterMain.NAME;
159    
160     /**
161     * This holds a reference to the
162     * system logger that is being used.
163     */
164     private Logger _logger = ReferenceManager.getInstance().getLogger();
165 tdb 1.28
166     /**
167     * A reference to the reference manager in use
168     */
169     private ReferenceManager _refman = ReferenceManager.getInstance();
170 tdb 1.8
171     //---STATIC ATTRIBUTES---
172    
173 pjm2 1.1 }