view src/main/java/alice/daemon/OutboundTcpConnection.java @ 346:d46c42352e4f

change images position. It is under src/main/resources
author sugi
date Mon, 21 Apr 2014 19:57:44 +0900
parents 8f71c3e6f11d
children 60eee1fb0fd3
line wrap: on
line source

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();
			}
		}
	}
	
}