ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/TCPDataHandler.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/TCPDataHandler.java (file contents):
Revision 1.1 by tdb, Mon Jan 22 01:41:46 2001 UTC vs.
Revision 1.2 by tdb, Mon Jan 22 02:57:38 2001 UTC

# Line 19 | Line 19 | import java.io.InputStreamReader;
19   * @author  $Author$
20   * @version $Id$
21   */
22 < class TCPDataHandler implements ClientDataHandler {
22 > class TCPDataHandler extends Thread {
23  
24   //---FINAL ATTRIBUTES---
25  
# Line 32 | Line 32 | class TCPDataHandler implements ClientDataHandler {
32  
33   //---CONSTRUCTORS---
34  
35 <    public TCPDataHandler(Socket socket) throws IOException {
35 >    public TCPDataHandler(Socket socket, Queue queue) throws IOException {
36          _socket = socket;
37 +        _queue = queue;
38 +        _queueID = queue.getQueue();
39          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
40          _socketOut = new PrintWriter(_socket.getOutputStream());
41          _logger.write(toString(), Logger.SYSINIT, "created");
42      }
43      
44   //---PUBLIC METHODS---
43
44    /**
45     * Sends inbound data to the client
46     *
47     * @param xml the data
48     */
49    public void receiveXML(String xml) {
50        _socketOut.println(xml);
51        _socketOut.flush();
52    }
45      
46 <    public void shutdown() throws IOException {
46 >    public void run() {
47 >        run = true;
48 >        while(run) {
49 >            try {
50 >                String xml = (String) _queue.get(_queueID);
51 >                _socketOut.println(xml);
52 >                _socketOut.flush();
53 >            }
54 >            catch(InvalidQueueException e) {
55 >                run = false;
56 >                _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
57 >            }
58 >        }
59          _logger.write(toString(), Logger.SYSMSG, "Shutting Down");
60 <        _socketOut.close();
61 <        _socketIn.close();
62 <        _socket.close();
60 >        try {
61 >            _socketOut.close();
62 >            _socketIn.close();
63 >            _socket.close();
64 >        }
65 >        catch(IOException e) {
66 >            _logger.write(toString(), Logger.ERROR, "Exception whilst shutting down: "+e);
67 >        }
68      }
69 +      
70 +    public void shutdown() {
71 +        run=false;
72 +    }
73      
74      /**
75       * Overrides the {@link java.lang.Object#toString() Object.toString()}
# Line 108 | Line 121 | class TCPDataHandler implements ClientDataHandler {
121      private PrintWriter _socketOut;
122      
123      private Socket _socket;
124 +    
125 +    private Queue _queue;
126 +    private int _queueID;
127 +    private boolean run;
128      
129   //---STATIC ATTRIBUTES---
130  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines