package leigh.continuity.line;

import leigh.continuity.net.SocketHandler;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

import java.io.IOException;
import java.net.Socket;

/**
 * This class processes an incoming socket connection on a new thread served by a {@link BasicLineHandler}.
 *
 * @author Alex Leigh
 */
public class BasicLineHandlerFactory implements SocketHandler {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(BasicLineHandlerFactory.class);
    private final LineProcessorFactory factory;

    public BasicLineHandlerFactory(LineProcessorFactory factory) {
        this.factory = factory;
    }

    @Override
    public void handle(Socket s) throws IOException {
        BasicLineHandler lineHandler = new BasicLineHandler(s);
        lineHandler.setLineProcessor(factory.build(lineHandler));
        new Thread(lineHandler).start();
    }
}
