--- projects/cms/source/conient/uk/org/iscream/cms/conient/DataReader.java 2001/01/22 03:03:39 1.6 +++ projects/cms/source/conient/uk/org/iscream/cms/conient/DataReader.java 2001/01/24 03:09:45 1.7 @@ -1,15 +1,17 @@ //---PACKAGE DECLARATION--- +package uk.ac.ukc.iscream.conient; //---IMPORTS--- import java.io.*; import uk.ac.ukc.iscream.util.*; /** - * Reads in bound data and presents it as it comes - * in for anything that wants it. + * The class reads in data from a BufferedReader, + * it then converts it to an XMLPacket and adds + * it to its Queue for anything that wants it. * * @author $Author: ajm $ - * @version $Id: DataReader.java,v 1.6 2001/01/22 03:03:39 ajm Exp $ + * @version $Id: DataReader.java,v 1.7 2001/01/24 03:09:45 ajm Exp $ */ public class DataReader extends Thread { @@ -18,12 +20,19 @@ public class DataReader extends Thread { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.6 $"; + public final String REVISION = "$Revision: 1.7 $"; //---STATIC METHODS--- //---CONSTRUCTORS--- + /** + * Constructs a new data reader, giving it its BufferedReader + * and Queue. + * + * @param inBound the BufferedReader this class should use + * @param dataQueue the queue new data should be placed on + */ public DataReader(BufferedReader inBound, Queue dataQueue) { _inBound = inBound; _dataQueue = dataQueue; @@ -31,35 +40,62 @@ public class DataReader extends Thread { //---PUBLIC METHODS--- + /** + * This thread reads data from the BufferedReader. + * It does this until either there is a problem + * or it is told to stop. + * + * Any data it reads it converts to XML and then + * adds to its queue. + */ public void run() { try { - + String line; + + // continue until we are told to stop while (_running) { - _dataQueue.add(_inBound.readLine()); + line = _inBound.readLine(); + _dataQueue.add(line); } - //tidy up some stuff here at some point + // close the BufferedReader _inBound.close(); } catch (IOException e) { - SwingClient.addMessage("Data Channel Shutdown: reason - "+e); - _running = false; + SwingClient.addMessage("Data Channel Shutdown: reason - "+e); + _running = false; } } + /** + * This method allows other classes + * to shutdown this data reader. + */ + public void shutdown() { + _running = false; + } + //---PRIVATE METHODS--- //---ACCESSOR/MUTATOR METHODS--- - public void setRunning(boolean running) { - _running = running; - } - //---ATTRIBUTES--- + /** + * The reader we are reading from. + */ BufferedReader _inBound; + + /** + * The Queue we place data on. + */ Queue _dataQueue; - boolean _running = true; + + /** + * The state of this thread. + */ + boolean _running = true; + //---STATIC ATTRIBUTES--- }