-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessInput.java
More file actions
65 lines (53 loc) · 1.77 KB
/
ProcessInput.java
File metadata and controls
65 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**********************************************************************
* This thread designed for processing message that node received
*
* Revise Time Description Author
* v1.0 2018/10/14 Initial YG
*
*********************************************************************/
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
public class ProcessInput extends Thread{
private SpanningTree spanning_tree = null;
private BroadcastService broadcast_service = null;
private SysInfo system = null;
private Socket sock;
public ProcessInput(Socket s) {
spanning_tree = SpanningTree.getInstance();
broadcast_service = BroadcastService.getInstance();
system = SysInfo.getInstance();
sock = s;
}
public void run() {
try {
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
SystemMsg message = null;
try {
message = (SystemMsg) is.readObject();
} catch (FileNotFoundException e1)
{
e1.printStackTrace();
} catch (IOException e1)
{
e1.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
is.close();
if (message.get_msg_type().equals("SPAN")) {
print("Receved spanning tree msg: " + message.get_spanning_tree_msg());
spanning_tree.process(message.get_spanning_tree_msg());
} else if (message.get_msg_type().equals("BRD")) {
broadcast_service.process(message.get_broadcast_service_msg());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void print(String s) {
// System.out.println(s);
}
}