4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.core.*; |
6 |
|
import uk.ac.ukc.iscream.filter.*; |
7 |
< |
import java.net.Socket; |
8 |
< |
import java.net.ServerSocket; |
9 |
< |
import java.io.OutputStream; |
10 |
< |
import java.io.IOException; |
11 |
< |
import java.net.InetAddress; |
12 |
< |
import java.net.UnknownHostException; |
13 |
< |
import org.omg.CORBA.*; |
14 |
< |
import org.omg.CosNaming.*; |
7 |
> |
import uk.ac.ukc.iscream.util.*; |
8 |
> |
import java.net.*; |
9 |
> |
import java.io.*; |
10 |
|
|
11 |
|
/** |
12 |
|
* A socket listener to listen for new hosts registering with the system. |
32 |
|
/** |
33 |
|
* Constructs a new listener |
34 |
|
* |
35 |
< |
* @param logger a reference to the logger we are using |
41 |
< |
* @param configManager a reference to the ConfigurationManager we are using |
42 |
< |
* @param port The port that the server will listen on. |
35 |
> |
* @param listenPort The port that the server will listen on. |
36 |
|
*/ |
37 |
< |
public HostListener(Logger logger, ConfigurationManager configManager, int port, NamingContextExt ncRef) { |
38 |
< |
_logger = logger; |
46 |
< |
_ncRef = ncRef; |
47 |
< |
_configManager = configManager; |
48 |
< |
_port = port; |
37 |
> |
public HostListener(int listenPort) { |
38 |
> |
_listenPort = listenPort; |
39 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
40 |
|
} |
41 |
|
|
51 |
|
* and then passing them off to other processes to deal with. |
52 |
|
*/ |
53 |
|
public void run(){ |
54 |
< |
ServerSocket listenPort=null; |
54 |
> |
ServerSocket listenSocket=null; |
55 |
|
// We use this boolean so we can break out of the while loop if we want |
56 |
|
boolean run = true; |
57 |
|
try{ |
58 |
|
// Setup the ServerSocket so that clients can connect |
59 |
< |
listenPort = new ServerSocket(_port); |
59 |
> |
listenSocket = new ServerSocket(_listenPort); |
60 |
|
} |
61 |
|
catch(IOException e){ |
62 |
|
} |
65 |
|
_logger.write(toString(), Logger.SYSMSG, "Server listening on " |
66 |
|
+InetAddress.getLocalHost().getHostName() |
67 |
|
+"/"+InetAddress.getLocalHost().getHostAddress() |
68 |
< |
+" port "+listenPort.getLocalPort()); |
68 |
> |
+" port "+listenSocket.getLocalPort()); |
69 |
|
} |
70 |
|
catch(UnknownHostException e){ |
71 |
|
_logger.write(toString(), Logger.SYSMSG, "Server listening on UnknownHost " |
72 |
< |
+"port "+listenPort.getLocalPort()); |
72 |
> |
+"port "+listenSocket.getLocalPort()); |
73 |
|
} |
74 |
|
// Loop round constantly until we decide to stop |
75 |
|
while(run){ |
77 |
|
try{ |
78 |
|
_logger.write(toString(), Logger.SYSMSG, "Waiting for Connection"); |
79 |
|
// This will block until a host connects - at which point we get a Socket |
80 |
< |
hostSocket = listenPort.accept(); |
80 |
> |
hostSocket = listenSocket.accept(); |
81 |
|
_logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString()); |
82 |
|
} |
83 |
|
catch(IOException e){ |
88 |
|
if(run){ |
89 |
|
try { |
90 |
|
// Setup the HostInit so it can carry on communications with the host |
91 |
< |
HostInit init = new HostInit(hostSocket, _configManager, _logger, _ncRef); |
91 |
> |
HostInit init = new HostInit(hostSocket); |
92 |
|
// and start it |
93 |
|
init.start(); |
94 |
|
} catch (IOException e) { |
119 |
|
/** |
120 |
|
* A reference to the logger the system is using |
121 |
|
*/ |
122 |
< |
Logger _logger; |
122 |
> |
Logger _logger = ReferenceManager.getInstance().getLogger(); |
123 |
|
|
124 |
|
/** |
135 |
– |
* A reference to the configurator the system is using |
136 |
– |
*/ |
137 |
– |
ConfigurationManager _configManager; |
138 |
– |
|
139 |
– |
/** |
125 |
|
* The port on which the server should listen. |
126 |
|
*/ |
127 |
< |
private int _port; |
143 |
< |
|
144 |
< |
private NamingContextExt _ncRef; |
127 |
> |
private int _listenPort; |
128 |
|
|
129 |
|
//---STATIC ATTRIBUTES--- |
130 |
|
|