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.17
Committed: Wed Feb 5 19:35:04 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.16: +3 -3 lines
Log Message:
Conient now uses the new seperate i-scream util package.

File Contents

# User Rev Content
1 tdb 1.15 /*
2     * i-scream central monitoring system
3 tdb 1.16 * http://www.i-scream.org.uk
4 tdb 1.15 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 ajm 1.1 //---PACKAGE DECLARATION---
22 tdb 1.14 package uk.org.iscream.cms.conient;
23 ajm 1.1
24     //---IMPORTS---
25     import java.io.*;
26 tdb 1.17 import uk.org.iscream.cms.util.*;
27 ajm 1.1
28     /**
29 ajm 1.7 * The class reads in data from a BufferedReader,
30     * it then converts it to an XMLPacket and adds
31     * it to its Queue for anything that wants it.
32 ajm 1.1 *
33 tdb 1.15 * @author $Author: tdb $
34 tdb 1.17 * @version $Id: DataReader.java,v 1.16 2002/05/21 16:47:10 tdb Exp $
35 ajm 1.1 */
36     public class DataReader extends Thread {
37    
38     //---FINAL ATTRIBUTES---
39    
40     /**
41     * The current CVS revision of this class
42     */
43 tdb 1.17 public final String REVISION = "$Revision: 1.16 $";
44 ajm 1.1
45     //---STATIC METHODS---
46    
47     //---CONSTRUCTORS---
48    
49 ajm 1.7 /**
50     * Constructs a new data reader, giving it its BufferedReader
51     * and Queue.
52     *
53     * @param inBound the BufferedReader this class should use
54     * @param dataQueue the queue new data should be placed on
55 ajm 1.12 * @param ch the connection handler in use
56 ajm 1.7 */
57 ajm 1.12 public DataReader(BufferedReader inBound, Queue dataQueue, ConnectionHandler ch) {
58     _ch = ch;
59 ajm 1.1 _inBound = inBound;
60 ajm 1.5 _dataQueue = dataQueue;
61 ajm 1.1 }
62    
63     //---PUBLIC METHODS---
64    
65 ajm 1.7 /**
66     * This thread reads data from the BufferedReader.
67     * It does this until either there is a problem
68     * or it is told to stop.
69     *
70 ajm 1.12 * If there is a problem it calls shutdownLinks in the
71     * ConnectionHandler.
72     *
73 ajm 1.7 * Any data it reads it converts to XML and then
74     * adds to its queue.
75     */
76 ajm 1.1 public void run() {
77 ajm 1.3 try {
78 ajm 1.7 String line;
79    
80     // continue until we are told to stop
81 ajm 1.6 while (_running) {
82 ajm 1.7 line = _inBound.readLine();
83 tdb 1.9 if (line == null) {
84     throw new IOException("unexpected loss of connection to server");
85     }
86 ajm 1.7 _dataQueue.add(line);
87 ajm 1.6 }
88    
89 ajm 1.7 // close the BufferedReader
90 ajm 1.6 _inBound.close();
91    
92 ajm 1.3 } catch (IOException e) {
93 ajm 1.10 Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e);
94 ajm 1.7 _running = false;
95 ajm 1.12 // tell the ConnectionHandler to shut down the links
96 ajm 1.13 _ch.shutdownDataLink();
97 ajm 1.1 }
98     }
99    
100 ajm 1.7 /**
101     * This method allows other classes
102     * to shutdown this data reader.
103     */
104     public void shutdown() {
105     _running = false;
106     }
107    
108 ajm 1.1 //---PRIVATE METHODS---
109    
110     //---ACCESSOR/MUTATOR METHODS---
111    
112     //---ATTRIBUTES---
113    
114 ajm 1.7 /**
115     * The reader we are reading from.
116     */
117 ajm 1.12 private BufferedReader _inBound;
118 ajm 1.7
119     /**
120     * The Queue we place data on.
121     */
122 ajm 1.12 private Queue _dataQueue;
123 ajm 1.7
124     /**
125     * The state of this thread.
126     */
127 ajm 1.12 private boolean _running = true;
128    
129     /**
130     * A reference to the ConnectionHandler in use
131     */
132     private ConnectionHandler _ch;
133 ajm 1.7
134 ajm 1.1 //---STATIC ATTRIBUTES---
135    
136     }