2 |
|
|
3 |
|
//---IMPORTS--- |
4 |
|
import java.io.*; |
5 |
+ |
import uk.ac.ukc.iscream.util.*; |
6 |
|
|
7 |
|
/** |
8 |
|
* Reads in bound data and presents it as it comes |
24 |
|
|
25 |
|
//---CONSTRUCTORS--- |
26 |
|
|
27 |
< |
public DataReader(BufferedReader inBound) { |
27 |
> |
public DataReader(BufferedReader inBound, Queue dataQueue) { |
28 |
|
_inBound = inBound; |
29 |
+ |
_dataQueue = dataQueue; |
30 |
|
} |
31 |
|
|
32 |
|
//---PUBLIC METHODS--- |
33 |
|
|
34 |
|
public void run() { |
35 |
< |
boolean running = true; |
36 |
< |
while (running){ |
37 |
< |
try { |
38 |
< |
|
37 |
< |
_xml = _inBound.readLine(); |
38 |
< |
synchronized (this) { |
39 |
< |
notifyAll(); |
40 |
< |
} |
35 |
> |
try { |
36 |
> |
|
37 |
> |
while (_running) { |
38 |
> |
_dataQueue.add(_inBound.readLine()); |
39 |
|
} |
40 |
< |
catch (IOException e) { |
41 |
< |
System.err.println("This DataReader thread has been shut down as an exception occured: "+e); |
42 |
< |
running = false; |
43 |
< |
return; |
44 |
< |
} |
40 |
> |
|
41 |
> |
//tidy up some stuff here at some point |
42 |
> |
_inBound.close(); |
43 |
> |
|
44 |
> |
} catch (IOException e) { |
45 |
> |
SwingClient.addMessage("Data Channel Shutdown: reason - "+e); |
46 |
> |
_running = false; |
47 |
|
} |
48 |
|
} |
49 |
|
|
51 |
|
|
52 |
|
//---ACCESSOR/MUTATOR METHODS--- |
53 |
|
|
54 |
< |
public String getXML() { |
55 |
< |
return _xml; |
54 |
> |
public void setRunning(boolean running) { |
55 |
> |
_running = running; |
56 |
|
} |
57 |
|
|
58 |
|
//---ATTRIBUTES--- |
59 |
|
|
60 |
|
BufferedReader _inBound; |
61 |
< |
String _xml; |
62 |
< |
|
61 |
> |
Queue _dataQueue; |
62 |
> |
boolean _running = true; |
63 |
|
//---STATIC ATTRIBUTES--- |
64 |
|
|
65 |
|
} |