ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/DataReader.java
Revision: 1.15
Committed: Sat May 18 18:15:56 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.14: +22 -3 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.15 /*
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 ajm 1.1 //---PACKAGE DECLARATION---
21 tdb 1.14 package uk.org.iscream.cms.conient;
22 ajm 1.1
23     //---IMPORTS---
24     import java.io.*;
25 tdb 1.14 import uk.org.iscream.cms.server.util.*;
26 ajm 1.1
27     /**
28 ajm 1.7 * The class reads in data from a BufferedReader,
29     * it then converts it to an XMLPacket and adds
30     * it to its Queue for anything that wants it.
31 ajm 1.1 *
32 tdb 1.15 * @author $Author: tdb $
33     * @version $Id: DataReader.java,v 1.14 2001/05/29 17:41:32 tdb Exp $
34 ajm 1.1 */
35     public class DataReader extends Thread {
36    
37     //---FINAL ATTRIBUTES---
38    
39     /**
40     * The current CVS revision of this class
41     */
42 tdb 1.15 public final String REVISION = "$Revision: 1.14 $";
43 ajm 1.1
44     //---STATIC METHODS---
45    
46     //---CONSTRUCTORS---
47    
48 ajm 1.7 /**
49     * Constructs a new data reader, giving it its BufferedReader
50     * and Queue.
51     *
52     * @param inBound the BufferedReader this class should use
53     * @param dataQueue the queue new data should be placed on
54 ajm 1.12 * @param ch the connection handler in use
55 ajm 1.7 */
56 ajm 1.12 public DataReader(BufferedReader inBound, Queue dataQueue, ConnectionHandler ch) {
57     _ch = ch;
58 ajm 1.1 _inBound = inBound;
59 ajm 1.5 _dataQueue = dataQueue;
60 ajm 1.1 }
61    
62     //---PUBLIC METHODS---
63    
64 ajm 1.7 /**
65     * This thread reads data from the BufferedReader.
66     * It does this until either there is a problem
67     * or it is told to stop.
68     *
69 ajm 1.12 * If there is a problem it calls shutdownLinks in the
70     * ConnectionHandler.
71     *
72 ajm 1.7 * Any data it reads it converts to XML and then
73     * adds to its queue.
74     */
75 ajm 1.1 public void run() {
76 ajm 1.3 try {
77 ajm 1.7 String line;
78    
79     // continue until we are told to stop
80 ajm 1.6 while (_running) {
81 ajm 1.7 line = _inBound.readLine();
82 tdb 1.9 if (line == null) {
83     throw new IOException("unexpected loss of connection to server");
84     }
85 ajm 1.7 _dataQueue.add(line);
86 ajm 1.6 }
87    
88 ajm 1.7 // close the BufferedReader
89 ajm 1.6 _inBound.close();
90    
91 ajm 1.3 } catch (IOException e) {
92 ajm 1.10 Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e);
93 ajm 1.7 _running = false;
94 ajm 1.12 // tell the ConnectionHandler to shut down the links
95 ajm 1.13 _ch.shutdownDataLink();
96 ajm 1.1 }
97     }
98    
99 ajm 1.7 /**
100     * This method allows other classes
101     * to shutdown this data reader.
102     */
103     public void shutdown() {
104     _running = false;
105     }
106    
107 ajm 1.1 //---PRIVATE METHODS---
108    
109     //---ACCESSOR/MUTATOR METHODS---
110    
111     //---ATTRIBUTES---
112    
113 ajm 1.7 /**
114     * The reader we are reading from.
115     */
116 ajm 1.12 private BufferedReader _inBound;
117 ajm 1.7
118     /**
119     * The Queue we place data on.
120     */
121 ajm 1.12 private Queue _dataQueue;
122 ajm 1.7
123     /**
124     * The state of this thread.
125     */
126 ajm 1.12 private boolean _running = true;
127    
128     /**
129     * A reference to the ConnectionHandler in use
130     */
131     private ConnectionHandler _ch;
132 ajm 1.7
133 ajm 1.1 //---STATIC ATTRIBUTES---
134    
135     }