4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.core.*; |
6 |
|
import uk.ac.ukc.iscream.filter.*; |
7 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
8 |
|
import java.net.Socket; |
9 |
|
import java.io.InputStream; |
10 |
|
import java.io.OutputStream; |
30 |
|
//---STATIC METHODS--- |
31 |
|
|
32 |
|
//---CONSTRUCTORS--- |
33 |
< |
|
34 |
< |
public TCPReaderInit(Socket socket, Filter parent) throws IOException { |
33 |
> |
|
34 |
> |
/** |
35 |
> |
* Construct a new TCPReaderInit. |
36 |
> |
* |
37 |
> |
* @param socket the Socket to which the host is connected |
38 |
> |
* @param queue the Queue to which we'll add data |
39 |
> |
* @throws IOException if something goes badly wrong |
40 |
> |
*/ |
41 |
> |
public TCPReaderInit(Socket socket, Queue queue) throws IOException { |
42 |
|
_socket = socket; |
43 |
< |
_parent = parent; |
43 |
> |
_queue = queue; |
44 |
> |
// setup the reader & writer |
45 |
|
_socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); |
46 |
|
_socketOut = new PrintWriter(_socket.getOutputStream()); |
47 |
|
_logger.write(toString(), Logger.SYSINIT, "created"); |
48 |
|
} |
49 |
|
|
50 |
|
//---PUBLIC METHODS--- |
51 |
< |
|
51 |
> |
|
52 |
> |
/** |
53 |
> |
* Main run method. Will communicate with the host, inform it |
54 |
> |
* if any updates to it's configuration are needed, and send |
55 |
> |
* a heartbeat packet into the system. |
56 |
> |
*/ |
57 |
|
public void run() { |
58 |
|
try { |
59 |
|
//variables |
114 |
|
String ipadd = _socket.getInetAddress().getHostAddress(); |
115 |
|
String xml = "<packet type=\"heartbeat\" machine_name=\""+hostname+"\" date=\""+date+"\" ip=\""+ipadd+"\"></packet>"; |
116 |
|
|
117 |
< |
FilterThread t = new FilterThread(xml, _parent); |
104 |
< |
t.start(); |
117 |
> |
_queue.add(xml); |
118 |
|
|
119 |
|
} catch (Exception e) { |
120 |
|
_logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage()); |
129 |
|
} catch (IOException e) { |
130 |
|
_logger.write(toString(), Logger.ERROR, "exception on socket close"); |
131 |
|
} |
132 |
< |
_logger.write(toString(), Logger.SYSMSG, "finished"); |
132 |
> |
_logger.write(toString(), Logger.DEBUG, "finished"); |
133 |
|
} |
134 |
|
|
135 |
|
/** |
192 |
|
PrintWriter _socketOut; |
193 |
|
|
194 |
|
/** |
195 |
< |
* A reference to our parent |
195 |
> |
* A reference to our Queue |
196 |
|
*/ |
197 |
< |
Filter _parent; |
197 |
> |
Queue _queue; |
198 |
|
//---STATIC ATTRIBUTES--- |
199 |
|
|
200 |
|
} |