345
|
1 package alice.daemon;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import alice.datasegment.Command;
|
|
5
|
|
6 public class OutboundTcpConnection extends Thread {
|
|
7
|
|
8 public Connection connection;
|
|
9
|
|
10 public OutboundTcpConnection(Connection connection) {
|
|
11 this.connection = connection;
|
|
12 }
|
|
13
|
|
14
|
|
15
|
|
16 /**
|
|
17 * pipeline thread for transmission
|
|
18 */
|
|
19 public void run() {
|
|
20 while (true) {
|
|
21 try {
|
|
22 Command cmd = connection.sendQueue.take();
|
|
23 switch (cmd.type) {
|
|
24 case CLOSE:
|
|
25 connection.socket.close();
|
|
26 return;
|
|
27 case FINISH:
|
|
28 System.exit(0);
|
|
29 return;
|
|
30 default:
|
|
31 break;
|
|
32 }
|
|
33 connection.write(cmd);
|
|
34 } catch (InterruptedException e) {
|
|
35 e.printStackTrace();
|
|
36 } catch (IOException e) {
|
|
37 e.printStackTrace();
|
|
38 }
|
|
39 }
|
|
40 }
|
|
41
|
|
42 }
|