3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.core.*; |
6 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
|
import uk.ac.ukc.iscream.filter.*; |
8 |
|
import java.net.Socket; |
9 |
|
import java.net.ServerSocket; |
14 |
|
import uk.ac.ukc.iscream.util.*; |
15 |
|
|
16 |
|
/** |
17 |
< |
* A socket listener to listen for new hosts registering with the system. |
17 |
< |
* When a host makes a connection, the connecton is past to an instance |
18 |
< |
* of the HostInit class, which handles further communication. |
17 |
> |
* Reads TCP Heartbeats from the host applications. |
18 |
|
* |
19 |
|
* @author $Author$ |
20 |
|
* @version $Id$ |
33 |
|
//---CONSTRUCTORS--- |
34 |
|
|
35 |
|
/** |
36 |
< |
* Constructs a new listener |
36 |
> |
* Constructs a new TCPReader |
37 |
|
* |
38 |
< |
* @param logger a reference to the logger we are using |
39 |
< |
* @param configManager a reference to the ConfigurationManager we are using |
41 |
< |
* @param port The port that the server will listen on. |
38 |
> |
* @param queue A reference to our Queue |
39 |
> |
* @param port The port that the TCPReader will listen on |
40 |
|
*/ |
41 |
< |
public TCPReader(int port, Filter parent) { |
41 |
> |
public TCPReader(int port, Queue queue) { |
42 |
|
_port = port; |
43 |
< |
_parent = parent; |
43 |
> |
_queue = queue; |
44 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
45 |
|
} |
46 |
|
|
80 |
|
while(run){ |
81 |
|
Socket hostSocket=null; |
82 |
|
try{ |
83 |
< |
_logger.write(toString(), Logger.SYSMSG, "Waiting for Connection"); |
83 |
> |
_logger.write(toString(), Logger.DEBUG, "Waiting for Connection"); |
84 |
|
// This will block until a host connects - at which point we get a Socket |
85 |
|
hostSocket = listenPort.accept(); |
86 |
< |
_logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString()); |
86 |
> |
_logger.write(toString(), Logger.DEBUG, "Connection accepted from: " + hostSocket.toString()); |
87 |
|
} |
88 |
|
catch(IOException e){ |
89 |
|
// Something went wrong with the ServerSocket, so we'll stop listening |
92 |
|
// If we've stopped on the line above we won't want to try this ! |
93 |
|
if(run){ |
94 |
|
try { |
95 |
< |
// Setup the HostInit so it can carry on communications with the host |
96 |
< |
TCPReaderInit init = new TCPReaderInit(hostSocket, _parent); |
95 |
> |
// Setup the TCPReaderInit and start it |
96 |
> |
TCPReaderInit init = new TCPReaderInit(hostSocket, _queue); |
97 |
|
// and start it |
98 |
|
init.start(); |
99 |
|
} catch (IOException e) { |
149 |
|
*/ |
150 |
|
private int _port; |
151 |
|
|
152 |
< |
private Filter _parent; |
152 |
> |
/** |
153 |
> |
* A reference to our Queue |
154 |
> |
*/ |
155 |
> |
private Queue _queue; |
156 |
|
|
157 |
|
//---STATIC ATTRIBUTES--- |
158 |
|
|