// Path: src/main/java/info/jdavid/ok/server/Logger.java
// static final org.slf4j.Logger logger = LoggerFactory.getLogger(HttpServer.class);


import java.io.Closeable;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocket;
import static info.jdavid.ok.server.Logger.logger;
      @Override public void run() {
        try {
          dispatchLoop(socket, secure, insecureOnly, https, hostname,
                       maxRequestSize, keepAliveStrategy, requestHandler);
        }
        finally {
          close(socket);
        }
      }
    }).start();
  }

  private void dispatchLoop(final ServerSocket socket,
                            final boolean secure, final boolean insecureOnly,
                            final @Nullable Https https,
                            final @Nullable String hostname,
                            final long maxRequestSize,
                            final KeepAliveStrategy keepAliveStrategy,
                            final RequestHandler requestHandler) {
    while (true) {
      try {
        if (!Thread.currentThread().isInterrupted()) {
          dispatch(new Request(socket.accept(), secure, insecureOnly, https, hostname,
                               maxRequestSize, keepAliveStrategy, requestHandler));
        }
      }
      catch (final IOException e) {
        if (socket.isClosed()) {
          break;
        }
// Path: src/main/java/info/jdavid/ok/server/Logger.java
// static final org.slf4j.Logger logger = LoggerFactory.getLogger(HttpServer.class);


// Path: src/main/java/info/jdavid/ok/server/SocketDispatcher.java
import java.io.Closeable;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocket;
import static info.jdavid.ok.server.Logger.logger;

      @Override public void run() {
        try {
          dispatchLoop(socket, secure, insecureOnly, https, hostname,
                       maxRequestSize, keepAliveStrategy, requestHandler);
        }
        finally {
          close(socket);
        }
      }
    }).start();
  }

  private void dispatchLoop(final ServerSocket socket,
                            final boolean secure, final boolean insecureOnly,
                            final @Nullable Https https,
                            final @Nullable String hostname,
                            final long maxRequestSize,
                            final KeepAliveStrategy keepAliveStrategy,
                            final RequestHandler requestHandler) {
    while (true) {
      try {
        if (!Thread.currentThread().isInterrupted()) {
          dispatch(new Request(socket.accept(), secure, insecureOnly, https, hostname,
                               maxRequestSize, keepAliveStrategy, requestHandler));
        }
      }
      catch (final IOException e) {
        if (socket.isClosed()) {
          break;
        }
        logger.warn(secure ? "HTTPS" : "HTTP", e);