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
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/DataReader.java (file contents):
Revision 1.5 by ajm, Sat Jan 20 16:06:53 2001 UTC vs.
Revision 1.11 by ajm, Thu Mar 15 01:05:46 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.org.iscream.conient;
3  
4   //---IMPORTS---
5   import java.io.*;
6 < import uk.ac.ukc.iscream.util.*;
6 > import uk.org.iscream.util.*;
7  
8   /**
9 < * Reads in bound data and presents it as it comes
10 < * in for anything that wants it.
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$
14   * @version $Id$
# Line 24 | Line 26 | public class DataReader extends Thread {
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 +     */
36      public DataReader(BufferedReader inBound, Queue dataQueue) {
37          _inBound = inBound;
38          _dataQueue = dataQueue;
# Line 31 | Line 40 | public class DataReader extends Thread {
40  
41   //---PUBLIC METHODS---
42  
43 +    /**
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      public void run() {
35        boolean running = true;
52          try {
53 <            while (true) {
54 <                _dataQueue.add(_inBound.readLine());
55 <                            }
53 >            String line;
54 >            
55 >            // continue until we are told to stop
56 >            while (_running) {
57 >                line = _inBound.readLine();
58 >                if (line == null) {
59 >                    throw new IOException("unexpected loss of connection to server");
60 >                }
61 >                _dataQueue.add(line);
62 >            }
63 >        
64 >            // close the BufferedReader
65 >            _inBound.close();
66 >        
67          } catch (IOException e) {
68 <                System.err.println("This DataReader thread has been shut down as an exception occured: "+e);
69 <                running = false;
43 <                return;
68 >            Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e);
69 >            _running = false;
70          }
71      }
72  
73 +    /**
74 +     * This method allows other classes
75 +     * to shutdown this data reader.
76 +     */
77 +    public void shutdown() {
78 +        _running = false;
79 +    }
80 +
81   //---PRIVATE METHODS---
82  
83   //---ACCESSOR/MUTATOR METHODS---
84  
85   //---ATTRIBUTES---
86  
87 +    /**
88 +     * The reader we are reading from.
89 +     */
90      BufferedReader _inBound;
91 +    
92 +    /**
93 +     * The Queue we place data on.
94 +     */
95      Queue _dataQueue;
96 <
96 >    
97 >    /**
98 >     * The state of this thread.
99 >     */
100 >    boolean _running = true;
101 >    
102   //---STATIC ATTRIBUTES---
103  
104   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines