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.10
Committed: Sun Jan 28 23:48:16 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.9: +4 -4 lines
Log Message:
fixed communication error handling issues, should now handle all errors nicely.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 ajm 1.7 package uk.ac.ukc.iscream.conient;
3 ajm 1.1
4     //---IMPORTS---
5     import java.io.*;
6 ajm 1.5 import uk.ac.ukc.iscream.util.*;
7 ajm 1.1
8     /**
9 ajm 1.7 * The class reads in data from a BufferedReader,
10     * it then converts it to an XMLPacket and adds
11     * it to its Queue for anything that wants it.
12 ajm 1.1 *
13 ajm 1.10 * @author $Author: tdb1 $
14     * @version $Id: DataReader.java,v 1.9 2001/01/24 13:56:48 tdb1 Exp $
15 ajm 1.1 */
16     public class DataReader extends Thread {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 ajm 1.10 public final String REVISION = "$Revision: 1.9 $";
24 ajm 1.1
25     //---STATIC METHODS---
26    
27     //---CONSTRUCTORS---
28    
29 ajm 1.7 /**
30     * Constructs a new data reader, giving it its BufferedReader
31     * and Queue.
32     *
33     * @param inBound the BufferedReader this class should use
34     * @param dataQueue the queue new data should be placed on
35     */
36 ajm 1.5 public DataReader(BufferedReader inBound, Queue dataQueue) {
37 ajm 1.1 _inBound = inBound;
38 ajm 1.5 _dataQueue = dataQueue;
39 ajm 1.1 }
40    
41     //---PUBLIC METHODS---
42    
43 ajm 1.7 /**
44     * This thread reads data from the BufferedReader.
45     * It does this until either there is a problem
46     * or it is told to stop.
47     *
48     * Any data it reads it converts to XML and then
49     * adds to its queue.
50     */
51 ajm 1.1 public void run() {
52 ajm 1.3 try {
53 ajm 1.7 String line;
54    
55     // continue until we are told to stop
56 ajm 1.6 while (_running) {
57 ajm 1.7 line = _inBound.readLine();
58 tdb 1.9 if (line == null) {
59     throw new IOException("unexpected loss of connection to server");
60     }
61 ajm 1.7 _dataQueue.add(line);
62 ajm 1.6 }
63    
64 ajm 1.7 // close the BufferedReader
65 ajm 1.6 _inBound.close();
66    
67 ajm 1.3 } catch (IOException e) {
68 ajm 1.10 Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e);
69 ajm 1.7 _running = false;
70 ajm 1.1 }
71     }
72    
73 ajm 1.7 /**
74     * This method allows other classes
75     * to shutdown this data reader.
76     */
77     public void shutdown() {
78     _running = false;
79     }
80    
81 ajm 1.1 //---PRIVATE METHODS---
82    
83     //---ACCESSOR/MUTATOR METHODS---
84    
85     //---ATTRIBUTES---
86    
87 ajm 1.7 /**
88     * The reader we are reading from.
89     */
90 ajm 1.1 BufferedReader _inBound;
91 ajm 1.7
92     /**
93     * The Queue we place data on.
94     */
95 ajm 1.5 Queue _dataQueue;
96 ajm 1.7
97     /**
98     * The state of this thread.
99     */
100     boolean _running = true;
101    
102 ajm 1.1 //---STATIC ATTRIBUTES---
103    
104     }