Fixed shutting down http server(?)

This commit is contained in:
FrozenCow 2011-03-11 15:22:14 +01:00
parent 612966734a
commit 47e1f20a15

View File

@ -14,7 +14,7 @@ public class HttpServer extends Thread {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
private ServerSocket sock = null; private ServerSocket sock = null;
private boolean running = false; private Thread listeningThread;
private InetAddress bindAddress; private InetAddress bindAddress;
private int port; private int port;
@ -28,14 +28,14 @@ public class HttpServer extends Thread {
public void startServer() throws IOException { public void startServer() throws IOException {
sock = new ServerSocket(port, 5, bindAddress); sock = new ServerSocket(port, 5, bindAddress);
running = true; listeningThread = this;
start(); start();
log.info("Dynmap WebServer started on " + bindAddress + ":" + port); log.info("Dynmap WebServer started on " + bindAddress + ":" + port);
} }
public void run() { public void run() {
try { try {
while (running) { while (listeningThread == Thread.currentThread()) {
try { try {
Socket socket = sock.accept(); Socket socket = sock.accept();
HttpServerConnection requestThread = new HttpServerConnection(socket, this); HttpServerConnection requestThread = new HttpServerConnection(socket, this);
@ -45,20 +45,21 @@ public class HttpServer extends Thread {
break; break;
} }
} }
log.info("map WebServer run() exiting"); log.info("Webserver shut down.");
} catch (Exception ex) { } catch (Exception ex) {
log.log(Level.SEVERE, "Exception on WebServer-thread", ex); log.log(Level.SEVERE, "Exception on WebServer-thread", ex);
} }
} }
public void shutdown() { public void shutdown() {
log.info("Shutting down webserver...");
try { try {
if (sock != null) { if (sock != null) {
sock.close(); sock.close();
} }
} catch (IOException e) { } catch (IOException e) {
log.info("map stop() got IOException while closing socket"); log.log(Level.INFO, "Exception while closing socket for webserver shutdown", e);
} }
running = false; listeningThread = null;
} }
} }