package de.teiesti.postie;

import org.pmw.tinylog.Logger;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Set;

public class Office {

	private ServerSocket serverSocket;

	private Postman blueprint;

	private Set<Postman> postmen;

	private Thread acceptor;

	public Office bind(ServerSocket socket) {
		// FIXME
		return this;
	}

	public Office spawn(Postman blueprint) {
		// FIXME
		return this;
	}

	public Office start() {
		acceptor = new Acceptor();
		acceptor.start();

		return this;
	}

	public Office stop() {
		// FIXME how to do this?
		return this;
	}

	private class Acceptor extends Thread {

	 	@Override
		public void run() {
			Socket socket;
			Postman postman;
			while (!isInterrupted()) {
				try {
					socket = serverSocket.accept();
					postman = blueprint.clone().bind(socket).start();
					postmen.add(postman);
				} catch (IOException e) {
					Logger.error(e);
					System.exit(1);
				}
			}

		}

	}

}

Revert "Prepare for the 0.2.0 release."
Revert "Prepare for the 0.2.0 release."

This reverts commit d8b8f6edd066bc929b8438ed03703babd856907e.
