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.6
Committed: Wed Nov 29 20:59:09 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.5: +9 -3 lines
Log Message:
Added the heartbeat packet being sent.

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
15 /**
16 * <ONE LINE DESCRIPTION>
17 * <DETAILED DESCRIPTION>
18 *
19 * @author $Author: tdb1 $
20 * @version $Id: TCPReaderInit.java,v 1.5 2000/11/29 19:26:00 tdb1 Exp $
21 */
22 class TCPReaderInit extends Thread {
23
24 //---FINAL ATTRIBUTES---
25
26 /**
27 * The current CVS revision of this class
28 */
29 public final String REVISION = "$Revision: 1.5 $";
30
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 //variables
51 String filelist = "";
52 String lastModified = "";
53 String inBound = "";
54
55 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
103 String date = new Long(System.currentTimeMillis()).toString();
104 String hostname = _socket.getInetAddress().getHostName();
105 String ipadd = _socket.getInetAddress().getHostAddress();
106 String xml = "<packet type=\"heartbeat\" machine_name=\""+hostname+"\" date=\""+date+"\" ip=\""+ipadd+"\"></packet>";
107
108 FilterThread t = new FilterThread(xml, _parent, _logRef);
109 t.start();
110
111 } catch (Exception e) {
112 _logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
113 }
114
115 _socketOut.flush();
116 // Disconnect streams & socket
117 try {
118 _socketIn.close();
119 _socketOut.close();
120 _socket.close();
121 } catch (IOException e) {
122 _logRef.write(toString(), Logger.ERROR, "exception on socket close");
123 }
124 _logRef.write(toString(), Logger.SYSMSG, "finished");
125 }
126
127 /**
128 * Overrides the {@link java.lang.Object#toString() Object.toString()}
129 * method to provide clean logging (every class should have this).
130 *
131 * @return the name of this class and its CVS revision
132 */
133 public String toString() {
134 return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
135 + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
136
137 }
138
139 //---PRIVATE METHODS---
140
141 //---ACCESSOR/MUTATOR METHODS---
142
143 //---ATTRIBUTES---
144
145 ConfigurationManager _configManager;
146 Logger _logRef;
147 Socket _socket;
148 BufferedReader _socketIn;
149 PrintWriter _socketOut;
150 Filter _parent;
151 //---STATIC ATTRIBUTES---
152
153 }