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