diff src/main/java/alice/daemon/OutboundTcpConnection.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children 60eee1fb0fd3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/daemon/OutboundTcpConnection.java	Wed Apr 16 18:26:07 2014 +0900
@@ -0,0 +1,42 @@
+package alice.daemon;
+
+import java.io.IOException;
+import alice.datasegment.Command;
+
+public class OutboundTcpConnection extends Thread {
+	
+	public Connection connection;
+	
+	public OutboundTcpConnection(Connection connection) {
+		this.connection = connection;
+	}
+	
+	
+	
+	/**
+	 * pipeline thread for transmission
+	 */
+	public void run() {
+		while (true) {
+			try {
+				Command cmd = connection.sendQueue.take();
+				switch (cmd.type) {
+				case CLOSE:
+					connection.socket.close();
+					return;
+				case FINISH:
+					System.exit(0);
+					return;
+				default:
+					break;
+				}
+				connection.write(cmd);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	
+}