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