ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/TCPReaderInit.java
Revision: 1.3
Committed: Mon Nov 27 21:48:44 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.2: +53 -2 lines
Log Message:
Added the functionality.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import uk.ac.ukc.iscream.core.*;
5 import uk.ac.ukc.iscream.filter.*;
6 import java.net.Socket;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9 import java.io.IOException;
10 import java.io.*;
11 import org.omg.CORBA.*;
12 import org.omg.CosNaming.*;
13
14 /**
15 * <ONE LINE DESCRIPTION>
16 * <DETAILED DESCRIPTION>
17 *
18 * @author $Author: tdb1 $
19 * @version $Id: TCPReaderInit.java,v 1.2 2000/11/27 10:23:32 tdb1 Exp $
20 */
21 class TCPReaderInit extends Thread {
22
23 //---FINAL ATTRIBUTES---
24
25 /**
26 * The current CVS revision of this class
27 */
28 public final String REVISION = "$Revision: 1.2 $";
29
30 //---STATIC METHODS---
31
32 //---CONSTRUCTORS---
33
34 public TCPReaderInit(Socket socket, ConfigurationManager configManager, Logger logRef, Filter parent) throws IOException {
35 _configManager = configManager;
36 _logRef = logRef;
37 _socket = socket;
38 _parent = parent;
39 _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
40 _socketOut = new PrintWriter(_socket.getOutputStream());
41 _logRef.write(toString(), Logger.SYSINIT, "created");
42 }
43
44 //---PUBLIC METHODS---
45
46 //NEED TO MAJORILY CHANGE THIS BIT !
47 public void run() {
48 try {
49 //variables
50 String filelist = "";
51 String lastModified = "";
52 String inBound = "";
53
54 inBound = _socketIn.readLine();
55 if(!inBound.equals("HEARTBEAT")) {
56 _socketOut.println("ERROR");
57 _socketOut.flush();
58 throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound);
59 } else {
60 _socketOut.println("OK");
61 _socketOut.flush();
62 }
63
64 inBound = _socketIn.readLine();
65 if(!inBound.equals("CONFIG")) {
66 _socketOut.println("ERROR");
67 _socketOut.flush();
68 throw new IOException("protocol error - expecting:CONFIG got:" + inBound);
69 } else {
70 _socketOut.println("OK");
71 _socketOut.flush();
72 }
73
74 inBound = _socketIn.readLine();
75 filelist = inBound;
76 _socketOut.println("OK");
77 _socketOut.flush();
78
79 inBound = _socketIn.readLine();
80 lastModified = inBound;
81
82 boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
83
84 if(newConfig) {
85 _socketOut.println("ERROR");
86 }
87 else {
88 _socketOut.println("OK");
89 }
90 _socketOut.flush();
91
92 inBound = _socketIn.readLine();
93 if(!inBound.equals("ENDHEARTBEAT")) {
94 _socketOut.println("ERROR");
95 _socketOut.flush();
96 throw new IOException("protocol error - expecting:ENDHEARTBEAT got:" + inBound);
97 } else {
98 _socketOut.println("OK");
99 _socketOut.flush();
100 }
101
102 } catch (Exception e) {
103 _logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
104 }
105
106 _socketOut.flush();
107 // Disconnect streams & socket
108 try {
109 _socketIn.close();
110 _socketOut.close();
111 _socket.close();
112 } catch (IOException e) {
113 _logRef.write(toString(), Logger.ERROR, "exception on socket close");
114 }
115 _logRef.write(toString(), Logger.SYSMSG, "finished");
116 }
117
118 /**
119 * Overrides the {@link java.lang.Object#toString() Object.toString()}
120 * method to provide clean logging (every class should have this).
121 *
122 * @return the name of this class and its CVS revision
123 */
124 public String toString() {
125 return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
126 + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
127
128 }
129
130 //---PRIVATE METHODS---
131
132 //---ACCESSOR/MUTATOR METHODS---
133
134 //---ATTRIBUTES---
135
136 ConfigurationManager _configManager;
137 Logger _logRef;
138 Socket _socket;
139 BufferedReader _socketIn;
140 PrintWriter _socketOut;
141 Filter _parent;
142 //---STATIC ATTRIBUTES---
143
144 }