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