1 |
+ |
/* |
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 |
|
//---PACKAGE DECLARATION--- |
21 |
< |
package uk.ac.ukc.iscream.conient; |
21 |
> |
package uk.org.iscream.cms.conient; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
|
import java.io.*; |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
25 |
> |
import uk.org.iscream.cms.server.util.*; |
26 |
|
|
27 |
|
/** |
28 |
|
* The class reads in data from a BufferedReader, |
51 |
|
* |
52 |
|
* @param inBound the BufferedReader this class should use |
53 |
|
* @param dataQueue the queue new data should be placed on |
54 |
+ |
* @param ch the connection handler in use |
55 |
|
*/ |
56 |
< |
public DataReader(BufferedReader inBound, Queue dataQueue) { |
56 |
> |
public DataReader(BufferedReader inBound, Queue dataQueue, ConnectionHandler ch) { |
57 |
> |
_ch = ch; |
58 |
|
_inBound = inBound; |
59 |
|
_dataQueue = dataQueue; |
60 |
|
} |
66 |
|
* It does this until either there is a problem |
67 |
|
* or it is told to stop. |
68 |
|
* |
69 |
+ |
* If there is a problem it calls shutdownLinks in the |
70 |
+ |
* ConnectionHandler. |
71 |
+ |
* |
72 |
|
* Any data it reads it converts to XML and then |
73 |
|
* adds to its queue. |
74 |
|
*/ |
79 |
|
// continue until we are told to stop |
80 |
|
while (_running) { |
81 |
|
line = _inBound.readLine(); |
82 |
+ |
if (line == null) { |
83 |
+ |
throw new IOException("unexpected loss of connection to server"); |
84 |
+ |
} |
85 |
|
_dataQueue.add(line); |
86 |
|
} |
87 |
|
|
89 |
|
_inBound.close(); |
90 |
|
|
91 |
|
} catch (IOException e) { |
92 |
< |
SwingClient.addMessage("Data Channel Shutdown: reason - "+e); |
92 |
> |
Conient.addMessage("WARNING{data reader}: inbound data stopped - "+e); |
93 |
|
_running = false; |
94 |
+ |
// tell the ConnectionHandler to shut down the links |
95 |
+ |
_ch.shutdownDataLink(); |
96 |
|
} |
97 |
|
} |
98 |
|
|
113 |
|
/** |
114 |
|
* The reader we are reading from. |
115 |
|
*/ |
116 |
< |
BufferedReader _inBound; |
116 |
> |
private BufferedReader _inBound; |
117 |
|
|
118 |
|
/** |
119 |
|
* The Queue we place data on. |
120 |
|
*/ |
121 |
< |
Queue _dataQueue; |
121 |
> |
private Queue _dataQueue; |
122 |
|
|
123 |
|
/** |
124 |
|
* The state of this thread. |
125 |
|
*/ |
126 |
< |
boolean _running = true; |
126 |
> |
private boolean _running = true; |
127 |
> |
|
128 |
> |
/** |
129 |
> |
* A reference to the ConnectionHandler in use |
130 |
> |
*/ |
131 |
> |
private ConnectionHandler _ch; |
132 |
|
|
133 |
|
//---STATIC ATTRIBUTES--- |
134 |
|
|