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.17
Committed: Thu Jan 18 23:16:21 2001 UTC (23 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.16: +4 -3 lines
Log Message:
Changes to reflect move of Component, ComponentStartException, and the
ReferenceManager from util to componentmanager.

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.componentmanager.*;
10 import uk.ac.ukc.iscream.filter.*;
11 import uk.ac.ukc.iscream.util.*;
12
13 /**
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 *
18 * Now grabs data from a single queue, rather than
19 * waiting to be contacted.
20 *
21 * @author $Author: pjm2 $
22 * @version $Id: FilterThread.java,v 1.16 2001/01/15 10:09:49 pjm2 Exp $
23 */
24 public class FilterThread extends Thread{
25
26 //---FINAL ATTRIBUTES---
27
28 /**
29 * The current CVS revision of this class
30 */
31 public final String REVISION = "$Revision: 1.16 $";
32
33 //---STATIC METHODS---
34
35 //---CONSTRUCTORS---
36
37 /**
38 * Class constructor.
39 */
40 public FilterThread(Queue queue, Filter parent){
41 _parent = parent;
42 _queue = queue;
43 _logger.write(toString(), Logger.DEBUG, "created");
44 }
45
46 //---PUBLIC METHODS---
47
48 /**
49 * Runs the thread
50 */
51 public void run(){
52 // get a queue for ourselves
53 int n = _queue.getQueue();
54 // keep these out here, saves recreating the object
55 String xml = null;
56 while(true) {
57 // get a String of xml
58 try {
59 xml = (String) _queue.get(n);
60 }
61 catch (InvalidQueueException e) {
62 _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
63 }
64
65 // Get a string without any null characters in it.
66 // -- maybe String.trim() would be better here ?
67 if (xml.indexOf(0) != -1) {
68 xml = xml.substring(0, xml.indexOf(0));
69 }
70 else {
71 xml = xml.substring(0, xml.length());
72 }
73
74
75 // Bundle the XML all on one line (saves space and simplifies
76 // the protocol between clientinterface and client.
77 StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n");
78 xml = "";
79 while (tokenizer.hasMoreTokens()) {
80 xml += tokenizer.nextToken();
81 }
82
83
84 // Use XMLPacketMaker to make an XMLPacket object.
85 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
86 XMLPacket packet = xmlPacketMaker.createXMLPacket();
87
88 if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) {
89 // packet is not null
90 // packet was not dropped by a plugin
91 // ... best pass it on !
92 _parent.receiveXML(xml);
93 }
94 else {
95 // either we had a null, or a plugin dropped it
96 _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
97 }
98 }
99 }
100
101 /**
102 * Overrides the {@link java.lang.Object#toString() Object.toString()}
103 * method to provide clean logging (every class should have this).
104 *
105 * This uses the uk.ac.ukc.iscream.util.NameFormat class
106 * to format the toString()
107 *
108 * @return the name of this class and its CVS revision
109 */
110 public String toString() {
111 return FormatName.getName(
112 _name,
113 getClass().getName(),
114 REVISION);
115 }
116
117 //---PRIVATE METHODS---
118
119 //---ACCESSOR/MUTATOR METHODS---
120
121 //---ATTRIBUTES---
122
123 /**
124 * Our parent filter
125 */
126 Filter _parent;
127
128 /**
129 * The Queue object
130 */
131 Queue _queue;
132
133 /**
134 * This is the friendly identifier of the
135 * component this class is running in.
136 * eg, a Filter may be called "filter1",
137 * If this class does not have an owning
138 * component, a name from the configuration
139 * can be placed here. This name could also
140 * be changed to null for utility classes.
141 */
142 private String _name = FilterMain.NAME;
143
144 /**
145 * This holds a reference to the
146 * system logger that is being used.
147 */
148 private Logger _logger = ReferenceManager.getInstance().getLogger();
149
150 //---STATIC ATTRIBUTES---
151
152 }