1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.filtermanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.core.*; |
6 |
|
import uk.ac.ukc.iscream.filter.*; |
7 |
+ |
import uk.ac.ukc.iscream.util.*; |
8 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
9 |
|
import java.net.Socket; |
7 |
– |
import java.io.InputStream; |
8 |
– |
import java.io.OutputStream; |
9 |
– |
import java.io.IOException; |
10 |
|
import java.io.*; |
11 |
– |
import org.omg.CORBA.*; |
12 |
– |
import org.omg.CosNaming.*; |
11 |
|
|
12 |
|
/** |
13 |
< |
* <ONE LINE DESCRIPTION> |
14 |
< |
* <DETAILED DESCRIPTION> |
13 |
> |
* Handles setting up a host. |
14 |
> |
* This class provides a host with appropriate configuration |
15 |
> |
* and a reference to a Filter to which it should pass data. |
16 |
|
* |
17 |
|
* @author $Author$ |
18 |
|
* @version $Id$ |
30 |
|
|
31 |
|
//---CONSTRUCTORS--- |
32 |
|
|
33 |
< |
public HostInit(Socket socket, ConfigurationManager configManager, Logger logRef, NamingContextExt ncRef) throws IOException { |
35 |
< |
_configManager = configManager; |
36 |
< |
_logRef = logRef; |
33 |
> |
public HostInit(Socket socket) throws IOException { |
34 |
|
_socket = socket; |
38 |
– |
_ncRef = ncRef; |
35 |
|
_socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); |
36 |
|
_socketOut = new PrintWriter(_socket.getOutputStream()); |
37 |
< |
_logRef.write(toString(), Logger.SYSINIT, "created"); |
37 |
> |
_logger.write(toString(), Logger.SYSINIT, "created"); |
38 |
|
} |
39 |
|
|
40 |
|
//---PUBLIC METHODS--- |
48 |
|
throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound); |
49 |
|
} |
50 |
|
|
51 |
< |
Configuration myConfig = _configManager.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase()); |
51 |
> |
Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase()); |
52 |
|
if (myConfig == null) { |
53 |
|
_socketOut.println("ERROR"); |
54 |
|
throw new IOException("error in host configuration"); |
90 |
|
|
91 |
|
// get the property |
92 |
|
try { |
93 |
< |
String returnedProperty = myConfig.getProperty(inBound); |
93 |
> |
String returnedProperty = myConfig.getProperty("Host."+inBound); |
94 |
|
|
95 |
|
_socketOut.println(returnedProperty); |
96 |
|
_socketOut.flush(); |
101 |
|
} |
102 |
|
inBound = _socketIn.readLine(); |
103 |
|
} |
104 |
< |
_logRef.write(toString(), Logger.SYSMSG, "configured host"); |
104 |
> |
_logger.write(toString(), Logger.SYSMSG, "configured host"); |
105 |
|
_socketOut.println("OK"); |
106 |
|
_socketOut.flush(); |
107 |
|
|
116 |
|
else { |
117 |
|
// send info |
118 |
|
String parentFilter = myConfig.getProperty("Host.filter"); |
119 |
< |
_logRef.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter); |
120 |
< |
org.omg.CORBA.Object objRef = _ncRef.resolve(_ncRef.to_name("iscream.Filter." + parentFilter)); |
125 |
< |
Filter filter = FilterHelper.narrow(objRef); |
119 |
> |
_logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter); |
120 |
> |
Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter)); |
121 |
|
_socketOut.println(filter.getHostName() + ";" |
122 |
|
+ filter.getUDPPort() + ";" |
123 |
|
+ filter.getTCPPort()); |
141 |
|
} |
142 |
|
|
143 |
|
} catch (Exception e) { |
144 |
< |
_logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage()); |
144 |
> |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
145 |
|
} |
146 |
|
|
147 |
|
_socketOut.flush(); |
151 |
|
_socketOut.close(); |
152 |
|
_socket.close(); |
153 |
|
} catch (IOException e) { |
154 |
< |
_logRef.write(toString(), Logger.ERROR, "exception on socket close"); |
154 |
> |
_logger.write(toString(), Logger.ERROR, "exception on socket close"); |
155 |
|
} |
156 |
< |
_logRef.write(toString(), Logger.SYSMSG, "finished"); |
156 |
> |
_logger.write(toString(), Logger.SYSMSG, "finished"); |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
161 |
|
* method to provide clean logging (every class should have this). |
162 |
|
* |
163 |
+ |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
164 |
+ |
* to format the toString() |
165 |
+ |
* |
166 |
|
* @return the name of this class and its CVS revision |
167 |
|
*/ |
168 |
|
public String toString() { |
169 |
< |
return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName() |
170 |
< |
+ "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
171 |
< |
|
169 |
> |
return FormatName.getName( |
170 |
> |
_name, |
171 |
> |
getClass().getName(), |
172 |
> |
REVISION); |
173 |
|
} |
174 |
|
|
175 |
|
//---PRIVATE METHODS--- |
178 |
|
|
179 |
|
//---ATTRIBUTES--- |
180 |
|
|
181 |
< |
ConfigurationManager _configManager; |
182 |
< |
Logger _logRef; |
183 |
< |
Socket _socket; |
184 |
< |
BufferedReader _socketIn; |
185 |
< |
PrintWriter _socketOut; |
186 |
< |
NamingContextExt _ncRef; |
181 |
> |
/** |
182 |
> |
* This holds a reference to the |
183 |
> |
* system logger that is being used. |
184 |
> |
*/ |
185 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
186 |
> |
|
187 |
> |
/** |
188 |
> |
* A reference to the Configuration Manager the system is using |
189 |
> |
*/ |
190 |
> |
private ConfigurationManager _configManager = ReferenceManager.getInstance().getCM(); |
191 |
> |
|
192 |
> |
/** |
193 |
> |
* This is the friendly identifier of the |
194 |
> |
* component this class is running in. |
195 |
> |
* eg, a Filter may be called "filter1", |
196 |
> |
* If this class does not have an owning |
197 |
> |
* component, a name from the configuration |
198 |
> |
* can be placed here. This name could also |
199 |
> |
* be changed to null for utility classes. |
200 |
> |
*/ |
201 |
> |
private String _name = FilterManager.NAME; |
202 |
> |
|
203 |
> |
/** |
204 |
> |
* The socket this class uses |
205 |
> |
*/ |
206 |
> |
private Socket _socket; |
207 |
> |
|
208 |
> |
/** |
209 |
> |
* Used for the input stream of this socket |
210 |
> |
*/ |
211 |
> |
private BufferedReader _socketIn; |
212 |
> |
|
213 |
> |
/** |
214 |
> |
* Used for the output stream of this socket |
215 |
> |
*/ |
216 |
> |
private PrintWriter _socketOut; |
217 |
> |
|
218 |
|
//---STATIC ATTRIBUTES--- |
219 |
|
|
220 |
|
} |