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
Revision: 1.1
Committed: Mon Jan 22 01:41:46 2001 UTC (23 years, 4 months ago) by tdb
Branch: MAIN
Log Message:
The Data Handler for a TCP Connection. Simply pumps XML until told to stop.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.clientinterface;
3
4 //---IMPORTS---
5 import uk.ac.ukc.iscream.util.*;
6 import uk.ac.ukc.iscream.componentmanager.*;
7 import uk.ac.ukc.iscream.core.*;
8 import java.net.Socket;
9 import java.io.InputStream;
10 import java.io.OutputStream;
11 import java.io.IOException;
12 import java.io.BufferedReader;
13 import java.io.PrintWriter;
14 import java.io.InputStreamReader;
15
16 /**
17 * Acts as a Data Handler to a TCP based client.
18 *
19 * @author $Author$
20 * @version $Id$
21 */
22 class TCPDataHandler implements ClientDataHandler {
23
24 //---FINAL ATTRIBUTES---
25
26 /**
27 * The current CVS revision of this class
28 */
29 public final String REVISION = "$Revision: 1.1 $";
30
31 //---STATIC METHODS---
32
33 //---CONSTRUCTORS---
34
35 public TCPDataHandler(Socket socket) throws IOException {
36 _socket = socket;
37 _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
38 _socketOut = new PrintWriter(_socket.getOutputStream());
39 _logger.write(toString(), Logger.SYSINIT, "created");
40 }
41
42 //---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 }
53
54 public void shutdown() throws IOException {
55 _logger.write(toString(), Logger.SYSMSG, "Shutting Down");
56 _socketOut.close();
57 _socketIn.close();
58 _socket.close();
59 }
60
61 /**
62 * Overrides the {@link java.lang.Object#toString() Object.toString()}
63 * method to provide clean logging (every class should have this).
64 *
65 * This uses the uk.ac.ukc.iscream.util.NameFormat class
66 * to format the toString()
67 *
68 * @return the name of this class and its CVS revision
69 */
70 public String toString() {
71 return FormatName.getName(
72 _name,
73 getClass().getName(),
74 REVISION);
75 }
76
77 //---PRIVATE METHODS---
78
79 //---ACCESSOR/MUTATOR METHODS---
80
81 //---ATTRIBUTES---
82
83 /**
84 * This is the friendly identifier of the
85 * component this class is running in.
86 * eg, a Filter may be called "filter1",
87 * If this class does not have an owning
88 * component, a name from the configuration
89 * can be placed here. This name could also
90 * be changed to null for utility classes.
91 */
92 private String _name = ClientInterfaceMain.NAME;
93
94 /**
95 * This holds a reference to the
96 * system logger that is being used.
97 */
98 private Logger _logger = ReferenceManager.getInstance().getLogger();
99
100 /**
101 * A hook to the inbound data from the socket
102 */
103 private BufferedReader _socketIn;
104
105 /**
106 * A hook to the outbound stream for the socket
107 */
108 private PrintWriter _socketOut;
109
110 private Socket _socket;
111
112 //---STATIC ATTRIBUTES---
113
114 }