1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.filter; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.core.*; |
47 |
|
//NEED TO MAJORILY CHANGE THIS BIT ! |
48 |
|
public void run() { |
49 |
|
try { |
50 |
< |
String inBound = _socketIn.readLine(); |
51 |
< |
if (!inBound.equals("STARTCONFIG")) { |
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 - expected:STARTCONFIG got:" + inBound); |
59 |
> |
throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound); |
60 |
> |
} else { |
61 |
> |
_socketOut.println("OK"); |
62 |
> |
_socketOut.flush(); |
63 |
|
} |
64 |
< |
|
65 |
< |
Configuration myConfig = _configManager.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase()); |
66 |
< |
if (myConfig == null) { |
64 |
> |
|
65 |
> |
inBound = _socketIn.readLine(); |
66 |
> |
if(!inBound.equals("CONFIG")) { |
67 |
|
_socketOut.println("ERROR"); |
68 |
< |
throw new IOException("error in host configuration"); |
68 |
> |
_socketOut.flush(); |
69 |
> |
throw new IOException("protocol error - expecting:CONFIG got:" + inBound); |
70 |
|
} else { |
71 |
|
_socketOut.println("OK"); |
72 |
|
_socketOut.flush(); |
73 |
< |
|
74 |
< |
// get lastmodified |
75 |
< |
inBound = _socketIn.readLine(); |
76 |
< |
if(!inBound.equals("LASTMODIFIED")) { |
77 |
< |
// protocol error |
78 |
< |
_socketOut.println("ERROR"); |
79 |
< |
_socketOut.flush(); |
80 |
< |
throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound); |
81 |
< |
} |
82 |
< |
else { |
83 |
< |
// send info |
84 |
< |
_socketOut.println(myConfig.getLastModified()); |
85 |
< |
_socketOut.flush(); |
86 |
< |
} |
87 |
< |
|
88 |
< |
// get config fileList |
79 |
< |
inBound = _socketIn.readLine(); |
80 |
< |
if(!inBound.equals("FILELIST")) { |
81 |
< |
// protocol error |
82 |
< |
_socketOut.println("ERROR"); |
83 |
< |
_socketOut.flush(); |
84 |
< |
throw new IOException("protocol error - expected:FILELIST got:" + inBound); |
85 |
< |
} |
86 |
< |
else { |
87 |
< |
// send info |
88 |
< |
_socketOut.println(myConfig.getFileList()); |
89 |
< |
_socketOut.flush(); |
90 |
< |
} |
91 |
< |
|
92 |
< |
// get properties |
93 |
< |
inBound = _socketIn.readLine(); |
94 |
< |
while(!inBound.equals("ENDCONFIG")) { |
95 |
< |
|
96 |
< |
// get the property |
97 |
< |
try { |
98 |
< |
String returnedProperty = myConfig.getProperty(inBound); |
99 |
< |
|
100 |
< |
_socketOut.println(returnedProperty); |
101 |
< |
_socketOut.flush(); |
102 |
< |
|
103 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
104 |
< |
_socketOut.println("ERROR"); |
105 |
< |
_socketOut.flush(); |
106 |
< |
} |
107 |
< |
inBound = _socketIn.readLine(); |
108 |
< |
} |
109 |
< |
_logRef.write(toString(), Logger.SYSMSG, "configured host"); |
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 |
< |
|
98 |
< |
// get filter reference |
99 |
< |
inBound = _socketIn.readLine(); |
100 |
< |
if(!inBound.equals("FILTER")) { |
116 |
< |
// protocol error |
117 |
< |
_socketOut.println("ERROR"); |
118 |
< |
_socketOut.flush(); |
119 |
< |
throw new IOException("protocol error - expected:FILTER got:" + inBound); |
120 |
< |
} |
121 |
< |
else { |
122 |
< |
// send info |
123 |
< |
String parentFilter = myConfig.getProperty("Host.filter"); |
124 |
< |
_logRef.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter); |
125 |
< |
org.omg.CORBA.Object objRef = _ncRef.resolve(_ncRef.to_name("iscream.Filter." + parentFilter)); |
126 |
< |
Filter filter = FilterHelper.narrow(objRef); |
127 |
< |
_socketOut.println(filter.getHostName() + ";" |
128 |
< |
+ filter.getUDPPort() + ";" |
129 |
< |
+ filter.getTCPPort()); |
130 |
< |
_socketOut.flush(); |
131 |
< |
} |
132 |
< |
|
133 |
< |
// confirm that all is ok |
134 |
< |
inBound = _socketIn.readLine(); |
135 |
< |
if(!inBound.equals("END")) { |
136 |
< |
// protocol error |
137 |
< |
_socketOut.println("ERROR"); |
138 |
< |
_socketOut.flush(); |
139 |
< |
throw new IOException("protocol error - expected:END got:" + inBound); |
140 |
< |
} |
141 |
< |
else { |
142 |
< |
// send ok |
143 |
< |
_socketOut.println("OK"); |
144 |
< |
_socketOut.flush(); |
145 |
< |
} |
146 |
< |
|
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()); |