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.8
Committed: Thu Nov 30 02:00:55 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.7: +12 -14 lines
Log Message:
Changed all classes so that references to the Logger and ConfigurationManager
are no longer passed around between classes. All of the classes now utilise
the new ReferenceManager, which makes life much easier.
Also tidied everything so that they all use the same conventions for attributes,
namely the _ prefix to the name.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.filter;
3
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 import uk.ac.ukc.iscream.refman.*;
15
16 /**
17 * <ONE LINE DESCRIPTION>
18 * <DETAILED DESCRIPTION>
19 *
20 * @author $Author: ajm4 $
21 * @version $Id: TCPReaderInit.java,v 1.7 2000/11/29 21:27:39 ajm4 Exp $
22 */
23 class TCPReaderInit extends Thread {
24
25 //---FINAL ATTRIBUTES---
26
27 /**
28 * The current CVS revision of this class
29 */
30 public final String REVISION = "$Revision: 1.7 $";
31
32 //---STATIC METHODS---
33
34 //---CONSTRUCTORS---
35
36 public TCPReaderInit(Socket socket, Filter parent) throws IOException {
37 _socket = socket;
38 _parent = parent;
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---
45
46 public void run() {
47 try {
48 //variables
49 String filelist = "";
50 String lastModified = "";
51 String inBound = "";
52
53 inBound = _socketIn.readLine();
54 if(!inBound.equals("HEARTBEAT")) {
55 _socketOut.println("ERROR");
56 _socketOut.flush();
57 throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound);
58 } else {
59 _socketOut.println("OK");
60 _socketOut.flush();
61 }
62
63 inBound = _socketIn.readLine();
64 if(!inBound.equals("CONFIG")) {
65 _socketOut.println("ERROR");
66 _socketOut.flush();
67 throw new IOException("protocol error - expecting:CONFIG got:" + inBound);
68 } else {
69 _socketOut.println("OK");
70 _socketOut.flush();
71 }
72
73 inBound = _socketIn.readLine();
74 filelist = inBound;
75 _socketOut.println("OK");
76 _socketOut.flush();
77
78 inBound = _socketIn.readLine();
79 lastModified = inBound;
80
81 boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
82
83 if(newConfig) {
84 _socketOut.println("ERROR");
85 }
86 else {
87 _socketOut.println("OK");
88 }
89 _socketOut.flush();
90
91 inBound = _socketIn.readLine();
92 if(!inBound.equals("ENDHEARTBEAT")) {
93 _socketOut.println("ERROR");
94 _socketOut.flush();
95 throw new IOException("protocol error - expecting:ENDHEARTBEAT got:" + inBound);
96 } else {
97 _socketOut.println("OK");
98 _socketOut.flush();
99 }
100
101 String date = new Long(System.currentTimeMillis()).toString();
102 String hostname = _socket.getInetAddress().getHostName();
103 String ipadd = _socket.getInetAddress().getHostAddress();
104 String xml = "<packet type=\"heartbeat\" machine_name=\""+hostname+"\" date=\""+date+"\" ip=\""+ipadd+"\"></packet>";
105
106 FilterThread t = new FilterThread(xml, _parent);
107 t.start();
108
109 } catch (Exception e) {
110 _logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
111 }
112
113 _socketOut.flush();
114 // Disconnect streams & socket
115 try {
116 _socketIn.close();
117 _socketOut.close();
118 _socket.close();
119 } catch (IOException e) {
120 _logger.write(toString(), Logger.ERROR, "exception on socket close");
121 }
122 _logger.write(toString(), Logger.SYSMSG, "finished");
123 }
124
125 /**
126 * Overrides the {@link java.lang.Object#toString() Object.toString()}
127 * method to provide clean logging (every class should have this).
128 *
129 * @return the name of this class and its CVS revision
130 */
131 public String toString() {
132 return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
133 + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
134
135 }
136
137 //---PRIVATE METHODS---
138
139 //---ACCESSOR/MUTATOR METHODS---
140
141 //---ATTRIBUTES---
142
143 ConfigurationManager _configManager = ReferenceManager.getInstance().getCM();
144 Logger _logger = ReferenceManager.getInstance().getLogger();
145 Socket _socket;
146 BufferedReader _socketIn;
147 PrintWriter _socketOut;
148 Filter _parent;
149 //---STATIC ATTRIBUTES---
150
151 }