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.35
Committed: Sat May 18 18:16:02 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.34: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.35 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 tdb 1.8 //---PACKAGE DECLARATION---
21 tdb 1.32 package uk.org.iscream.cms.server.filter;
22 tdb 1.8
23     //---IMPORTS---
24 pjm2 1.1 import java.io.*;
25     import java.net.*;
26     import java.util.*;
27 tdb 1.32 import uk.org.iscream.cms.server.core.*;
28     import uk.org.iscream.cms.server.componentmanager.*;
29     import uk.org.iscream.cms.server.filter.*;
30     import uk.org.iscream.cms.server.util.*;
31 pjm2 1.1
32 tdb 1.8 /**
33 ajm 1.14 * Handle an incoming packet as a separate thread.
34     * Passes the data through various plugins, then
35     * passes it on to the parent filter.
36 tdb 1.8 *
37 tdb 1.15 * Now grabs data from a single queue, rather than
38     * waiting to be contacted.
39     *
40 tdb 1.33 * @author $Author: tdb $
41 tdb 1.35 * @version $Id: FilterThread.java,v 1.34 2002/03/22 16:42:54 tdb Exp $
42 tdb 1.8 */
43 tdb 1.2 public class FilterThread extends Thread{
44 pjm2 1.1
45 tdb 1.8 //---FINAL ATTRIBUTES---
46    
47     /**
48     * The current CVS revision of this class
49     */
50 tdb 1.35 public final String REVISION = "$Revision: 1.34 $";
51 tdb 1.8
52     //---STATIC METHODS---
53    
54     //---CONSTRUCTORS---
55 tdb 1.15
56 ajm 1.14 /**
57 tdb 1.18 * Constructs an instance of a FilterThread
58     *
59     * @param queue the Queue this filter is using
60 ajm 1.14 */
61 tdb 1.28 public FilterThread(Queue queue){
62 tdb 1.27 // set the Thread name
63     setName("filter.FilterThread");
64    
65 tdb 1.15 _queue = queue;
66 tdb 1.19 _logger.write(toString(), Logger.SYSINIT, "created");
67 pjm2 1.1 }
68 tdb 1.8
69     //---PUBLIC METHODS---
70    
71 ajm 1.14 /**
72 tdb 1.18 * Runs the thread, getting data from the Queue and
73     * sending it on to the parent filter.
74 ajm 1.14 */
75 pjm2 1.1 public void run(){
76 tdb 1.26 // setup the XMLPacketMaker
77     XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
78 tdb 1.15 // get a queue for ourselves
79     int n = _queue.getQueue();
80 pjm2 1.16 // keep these out here, saves recreating the object
81 tdb 1.15 String xml = null;
82 tdb 1.30 String parentFilterName = "";
83     Filter parent = null;
84 tdb 1.15 while(true) {
85     // get a String of xml
86     try {
87     xml = (String) _queue.get(n);
88     }
89     catch (InvalidQueueException e) {
90     _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
91     }
92    
93     // Get a string without any null characters in it.
94     // -- maybe String.trim() would be better here ?
95     if (xml.indexOf(0) != -1) {
96     xml = xml.substring(0, xml.indexOf(0));
97     }
98 pjm2 1.16
99     // Bundle the XML all on one line (saves space and simplifies
100 tdb 1.18 // the protocol between clientinterface and client).
101 pjm2 1.16 StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n");
102     xml = "";
103     while (tokenizer.hasMoreTokens()) {
104     xml += tokenizer.nextToken();
105     }
106 tdb 1.15
107     // Use XMLPacketMaker to make an XMLPacket object.
108 tdb 1.25 XMLPacket packet = null;
109     try {
110 tdb 1.26 packet = xmlPacketMaker.createXMLPacket(xml);
111 tdb 1.25 } catch(InvalidXMLException e) {
112     _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
113     // skip the rest of this loop iteration
114     continue;
115     }
116 tdb 1.28
117     // get parent
118     try {
119 tdb 1.33 String newParent = ConfigurationProxy.getInstance().getProperty("Filter." + FilterMain.NAME, "Filter.parentFilter");
120 tdb 1.30 if(!parentFilterName.equals(newParent)) {
121 tdb 1.31 parentFilterName = newParent;
122 tdb 1.30 parent = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName));
123     _logger.write(toString(), Logger.DEBUG, "Parent filter changed to: "+parentFilterName);
124     }
125 tdb 1.28 } catch (PropertyNotFoundException e) {
126     continue;
127     }
128    
129     // XMLPacket is ok, run filters...
130 tdb 1.25 if(PluginFilterManager.getInstance().runFilters(packet)) {
131     // and pass it on...
132 tdb 1.28 parent.receiveXML(xml);
133 tdb 1.15 }
134     else {
135 tdb 1.25 // ... or filtered it
136     _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
137 tdb 1.15 }
138 pjm2 1.1 }
139     }
140 tdb 1.8
141     /**
142     * Overrides the {@link java.lang.Object#toString() Object.toString()}
143     * method to provide clean logging (every class should have this).
144     *
145 tdb 1.32 * This uses the uk.org.iscream.cms.server.util.NameFormat class
146 ajm 1.14 * to format the toString()
147     *
148 tdb 1.8 * @return the name of this class and its CVS revision
149     */
150     public String toString() {
151 ajm 1.14 return FormatName.getName(
152     _name,
153     getClass().getName(),
154     REVISION);
155 tdb 1.8 }
156    
157     //---PRIVATE METHODS---
158    
159     //---ACCESSOR/MUTATOR METHODS---
160    
161     //---ATTRIBUTES---
162 ajm 1.14
163     /**
164 tdb 1.15 * The Queue object
165 ajm 1.14 */
166 tdb 1.15 Queue _queue;
167 ajm 1.14
168     /**
169     * This is the friendly identifier of the
170     * component this class is running in.
171     * eg, a Filter may be called "filter1",
172     * If this class does not have an owning
173     * component, a name from the configuration
174     * can be placed here. This name could also
175     * be changed to null for utility classes.
176     */
177     private String _name = FilterMain.NAME;
178    
179     /**
180     * This holds a reference to the
181     * system logger that is being used.
182     */
183     private Logger _logger = ReferenceManager.getInstance().getLogger();
184 tdb 1.28
185     /**
186     * A reference to the reference manager in use
187     */
188     private ReferenceManager _refman = ReferenceManager.getInstance();
189 tdb 1.8
190     //---STATIC ATTRIBUTES---
191    
192 pjm2 1.1 }