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.12
Committed: Fri Mar 23 03:58:26 2001 UTC (23 years, 1 month ago) by ajm
Branch: MAIN
Changes since 1.11: +18 -6 lines
Log Message:
DataReader can now shutdown the links if it detects a read error

More tidying in the ConfigDialog...all done now.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.conient;
3
4 //---IMPORTS---
5 import java.io.*;
6 import uk.org.iscream.util.*;
7
8 /**
9 * 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 *
13 * @author $Author: ajm4 $
14 * @version $Id: DataReader.java,v 1.11 2001/03/15 01:05:46 ajm4 Exp $
15 */
16 public class DataReader extends Thread {
17
18 //---FINAL ATTRIBUTES---
19
20 /**
21 * The current CVS revision of this class
22 */
23 public final String REVISION = "$Revision: 1.11 $";
24
25 //---STATIC METHODS---
26
27 //---CONSTRUCTORS---
28
29 /**
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 * @param ch the connection handler in use
36 */
37 public DataReader(BufferedReader inBound, Queue dataQueue, ConnectionHandler ch) {
38 _ch = ch;
39 _inBound = inBound;
40 _dataQueue = dataQueue;
41 }
42
43 //---PUBLIC METHODS---
44
45 /**
46 * This thread reads data from the BufferedReader.
47 * It does this until either there is a problem
48 * or it is told to stop.
49 *
50 * If there is a problem it calls shutdownLinks in the
51 * ConnectionHandler.
52 *
53 * Any data it reads it converts to XML and then
54 * adds to its queue.
55 */
56 public void run() {
57 try {
58 String line;
59
60 // continue until we are told to stop
61 while (_running) {
62 line = _inBound.readLine();
63 if (line == null) {
64 throw new IOException("unexpected loss of connection to server");
65 }
66 _dataQueue.add(line);
67 }
68
69 // close the BufferedReader
70 _inBound.close();
71
72 } catch (IOException e) {
73 Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e);
74 _running = false;
75 // tell the ConnectionHandler to shut down the links
76 _ch.shutdownLinks();
77 }
78 }
79
80 /**
81 * This method allows other classes
82 * to shutdown this data reader.
83 */
84 public void shutdown() {
85 _running = false;
86 }
87
88 //---PRIVATE METHODS---
89
90 //---ACCESSOR/MUTATOR METHODS---
91
92 //---ATTRIBUTES---
93
94 /**
95 * The reader we are reading from.
96 */
97 private BufferedReader _inBound;
98
99 /**
100 * The Queue we place data on.
101 */
102 private Queue _dataQueue;
103
104 /**
105 * The state of this thread.
106 */
107 private boolean _running = true;
108
109 /**
110 * A reference to the ConnectionHandler in use
111 */
112 private ConnectionHandler _ch;
113
114 //---STATIC ATTRIBUTES---
115
116 }