54 |
|
* the host to determine it's setup. |
55 |
|
*/ |
56 |
|
public void run() { |
57 |
+ |
// get a hook on the config proxy |
58 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
59 |
+ |
// this is our config name |
60 |
+ |
String configName = "Host." + _socket.getInetAddress().getHostName().toLowerCase(); |
61 |
|
try { |
62 |
< |
String inBound = _socketIn.readLine(); |
63 |
< |
if (!inBound.equals("STARTCONFIG")) { |
64 |
< |
_socketOut.println("ERROR"); |
65 |
< |
throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound); |
66 |
< |
} |
67 |
< |
|
68 |
< |
Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase()); |
69 |
< |
if (myConfig == null) { |
70 |
< |
_socketOut.println("ERROR"); |
71 |
< |
throw new IOException("error in host configuration"); |
72 |
< |
} else { |
73 |
< |
_socketOut.println("OK"); |
74 |
< |
|
75 |
< |
// get lastmodified |
76 |
< |
inBound = _socketIn.readLine(); |
77 |
< |
if(!inBound.equals("LASTMODIFIED")) { |
78 |
< |
// protocol error |
62 |
> |
// try for STARTCONFIG |
63 |
> |
getInBound("STARTCONFIG"); |
64 |
> |
_socketOut.println("OK"); |
65 |
> |
|
66 |
> |
// try for LASTMODIFIED |
67 |
> |
getInBound("LASTMODIFIED"); |
68 |
> |
_socketOut.println(cp.getLastModified(configName)); |
69 |
> |
|
70 |
> |
// try for FILELIST |
71 |
> |
getInBound("FILELIST"); |
72 |
> |
_socketOut.println(cp.getFileList(configName)); |
73 |
> |
|
74 |
> |
// try for FQDN |
75 |
> |
getInBound("FQDN"); |
76 |
> |
_socketOut.println(_socket.getInetAddress().getHostName().toLowerCase()); |
77 |
> |
|
78 |
> |
// get properties |
79 |
> |
String reqProperty = getInBound(); |
80 |
> |
while(!reqProperty.equals("ENDCONFIG")) { |
81 |
> |
// get the property |
82 |
> |
try { |
83 |
> |
String returnedProperty = cp.getProperty(configName, "Host."+reqProperty); |
84 |
> |
_socketOut.println(returnedProperty); |
85 |
> |
} catch (PropertyNotFoundException e) { |
86 |
|
_socketOut.println("ERROR"); |
76 |
– |
throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound); |
87 |
|
} |
88 |
< |
else { |
89 |
< |
// send info |
90 |
< |
_socketOut.println(myConfig.getLastModified()); |
88 |
> |
// get the next request |
89 |
> |
reqProperty = _socketIn.readLine(); |
90 |
> |
} |
91 |
> |
_logger.write(toString(), Logger.SYSMSG, "configured host"); |
92 |
> |
_socketOut.println("OK"); |
93 |
> |
|
94 |
> |
// get filter reference |
95 |
> |
getInBound("FILTER"); |
96 |
> |
// send info |
97 |
> |
String filterList = cp.getProperty(configName, "Host.filter"); |
98 |
> |
Filter filterRef = null; |
99 |
> |
String filter = null; |
100 |
> |
StringTokenizer st = new StringTokenizer(filterList, ";"); |
101 |
> |
while (filterRef==null && st.hasMoreTokens()) { |
102 |
> |
filter = st.nextToken(); |
103 |
> |
_logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter); |
104 |
> |
try { |
105 |
> |
filterRef = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + filter)); |
106 |
> |
} catch (ComponentCORBAException e) { |
107 |
> |
_logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter); |
108 |
|
} |
82 |
– |
|
83 |
– |
// get config fileList |
84 |
– |
inBound = _socketIn.readLine(); |
85 |
– |
if(!inBound.equals("FILELIST")) { |
86 |
– |
// protocol error |
87 |
– |
_socketOut.println("ERROR"); |
88 |
– |
throw new IOException("protocol error - expected:FILELIST got:" + inBound); |
89 |
– |
} |
90 |
– |
else { |
91 |
– |
// send info |
92 |
– |
_socketOut.println(myConfig.getFileList()); |
93 |
– |
} |
94 |
– |
|
95 |
– |
// send the FQDN to the host |
96 |
– |
inBound = _socketIn.readLine(); |
97 |
– |
if(!inBound.equals("FQDN")) { |
98 |
– |
// protocol error |
99 |
– |
_socketOut.println("ERROR"); |
100 |
– |
throw new IOException("protocol error - expected:FQDN got:" + inBound); |
101 |
– |
} |
102 |
– |
else { |
103 |
– |
// send the fqdn (of the host) to the host |
104 |
– |
_socketOut.println(_socket.getInetAddress().getHostName().toLowerCase()); |
105 |
– |
} |
106 |
– |
|
107 |
– |
// get properties |
108 |
– |
inBound = _socketIn.readLine(); |
109 |
– |
while(!inBound.equals("ENDCONFIG")) { |
110 |
– |
|
111 |
– |
// get the property |
112 |
– |
try { |
113 |
– |
String returnedProperty = myConfig.getProperty("Host."+inBound); |
114 |
– |
|
115 |
– |
_socketOut.println(returnedProperty); |
116 |
– |
|
117 |
– |
} catch (org.omg.CORBA.MARSHAL e) { |
118 |
– |
_socketOut.println("ERROR"); |
119 |
– |
} |
120 |
– |
inBound = _socketIn.readLine(); |
121 |
– |
} |
122 |
– |
_logger.write(toString(), Logger.SYSMSG, "configured host"); |
123 |
– |
_socketOut.println("OK"); |
124 |
– |
|
125 |
– |
// get filter reference |
126 |
– |
inBound = _socketIn.readLine(); |
127 |
– |
if(!inBound.equals("FILTER")) { |
128 |
– |
// protocol error |
129 |
– |
_socketOut.println("ERROR"); |
130 |
– |
throw new IOException("protocol error - expected:FILTER got:" + inBound); |
131 |
– |
} |
132 |
– |
else { |
133 |
– |
// send info |
134 |
– |
String filterList = myConfig.getProperty("Host.filter"); |
135 |
– |
Filter filterRef = null; |
136 |
– |
String filter = null; |
137 |
– |
StringTokenizer st = new StringTokenizer(filterList, ";"); |
138 |
– |
while (filterRef==null && st.hasMoreTokens()) { |
139 |
– |
filter = st.nextToken(); |
140 |
– |
_logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter); |
141 |
– |
try { |
142 |
– |
filterRef = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + filter)); |
143 |
– |
} catch (ComponentCORBAException e) { |
144 |
– |
_logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter); |
145 |
– |
} |
146 |
– |
} |
147 |
– |
|
148 |
– |
// hopefully we found a filter |
149 |
– |
if(filterRef != null) { |
150 |
– |
_logger.write(toString(), Logger.DEBUG, " found filter- " + filter); |
151 |
– |
// tell the host about it... |
152 |
– |
_socketOut.println(filterRef.getHostName() + ";" |
153 |
– |
+ filterRef.getUDPPort() + ";" |
154 |
– |
+ filterRef.getTCPPort()); |
155 |
– |
} |
156 |
– |
else { |
157 |
– |
// ...or throw a wobbly (and tell the host!) |
158 |
– |
_socketOut.println("ERROR"); |
159 |
– |
throw new IOException("unable to find filter for host"); |
160 |
– |
} |
161 |
– |
} |
162 |
– |
|
163 |
– |
// confirm that all is ok |
164 |
– |
inBound = _socketIn.readLine(); |
165 |
– |
if(!inBound.equals("END")) { |
166 |
– |
// protocol error |
167 |
– |
_socketOut.println("ERROR"); |
168 |
– |
throw new IOException("protocol error - expected:END got:" + inBound); |
169 |
– |
} |
170 |
– |
else { |
171 |
– |
// send ok |
172 |
– |
_socketOut.println("OK"); |
173 |
– |
} |
174 |
– |
|
109 |
|
} |
110 |
+ |
|
111 |
+ |
// hopefully we found a filter |
112 |
+ |
if(filterRef != null) { |
113 |
+ |
_logger.write(toString(), Logger.DEBUG, " found filter- " + filter); |
114 |
+ |
// tell the host about it... |
115 |
+ |
_socketOut.println(filterRef.getHostName() + ";" |
116 |
+ |
+ filterRef.getUDPPort() + ";" |
117 |
+ |
+ filterRef.getTCPPort()); |
118 |
+ |
} |
119 |
+ |
else { |
120 |
+ |
// ...or throw a wobbly (and tell the host!) |
121 |
+ |
_socketOut.println("ERROR"); |
122 |
+ |
throw new IOException("unable to find filter for host"); |
123 |
+ |
} |
124 |
|
|
125 |
+ |
// confirm ok with END |
126 |
+ |
getInBound("END"); |
127 |
+ |
_socketOut.println("OK"); |
128 |
+ |
|
129 |
|
} catch (Exception e) { |
130 |
|
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
131 |
|
} |
132 |
|
|
181 |
– |
_socketOut.flush(); |
133 |
|
// Disconnect streams & socket |
134 |
|
try { |
135 |
|
_socketIn.close(); |
158 |
|
} |
159 |
|
|
160 |
|
//---PRIVATE METHODS--- |
161 |
+ |
|
162 |
+ |
private String getInBound(String expected) throws IOException { |
163 |
+ |
// grab the input |
164 |
+ |
String inBound = getInBound(); |
165 |
+ |
// check if it's what we're expecting |
166 |
+ |
if(!inBound.equals(expected)) { |
167 |
+ |
throw new IOException("protocol error - expected:"+expected+" got:" + inBound); |
168 |
+ |
} |
169 |
+ |
// it should be ok then |
170 |
+ |
return inBound; |
171 |
+ |
} |
172 |
+ |
|
173 |
+ |
private String getInBound() throws IOException { |
174 |
+ |
// grab the input |
175 |
+ |
String inBound = _socketIn.readLine(); |
176 |
+ |
// check for null's, likely disconnection |
177 |
+ |
if(inBound == null) { |
178 |
+ |
throw new IOException("got null from host, maybe it died"); |
179 |
+ |
} |
180 |
+ |
// it's a valid message it seems |
181 |
+ |
return inBound; |
182 |
+ |
} |
183 |
|
|
184 |
|
//---ACCESSOR/MUTATOR METHODS--- |
185 |
|
|