mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-25 20:16:00 +01:00
Small webserver code-style improvements
This commit is contained in:
parent
a23178f772
commit
07932506fd
@ -120,9 +120,9 @@ public void load() throws IOException, ParseResourceException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webServer = new WebServer(
|
webServer = new WebServer(
|
||||||
|
webServerConfig.getWebserverBindAddress(),
|
||||||
webServerConfig.getWebserverPort(),
|
webServerConfig.getWebserverPort(),
|
||||||
webServerConfig.getWebserverMaxConnections(),
|
webServerConfig.getWebserverMaxConnections(),
|
||||||
webServerConfig.getWebserverBindAddress(),
|
|
||||||
requestHandler,
|
requestHandler,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.bluecolored.bluemap.core.webserver;
|
package de.bluecolored.bluemap.core.webserver;
|
||||||
|
|
||||||
|
import de.bluecolored.bluemap.core.logger.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
@ -34,26 +36,28 @@
|
|||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import de.bluecolored.bluemap.core.logger.Logger;
|
|
||||||
|
|
||||||
public class WebServer extends Thread {
|
public class WebServer extends Thread {
|
||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
private final int maxConnections;
|
private final int maxConnections;
|
||||||
private final InetAddress bindAdress;
|
private final InetAddress bindAddress;
|
||||||
private final boolean verbose;
|
private final boolean verbose;
|
||||||
|
|
||||||
private HttpRequestHandler handler;
|
private final HttpRequestHandler handler;
|
||||||
|
|
||||||
private ThreadPoolExecutor connectionThreads;
|
private ThreadPoolExecutor connectionThreads;
|
||||||
|
|
||||||
private ServerSocket server;
|
private ServerSocket server;
|
||||||
|
|
||||||
public WebServer(int port, int maxConnections, InetAddress bindAdress, HttpRequestHandler handler, boolean verbose) {
|
public WebServer(InetAddress bindAddress, int port, int maxConnections, HttpRequestHandler handler) {
|
||||||
|
this(bindAddress, port, maxConnections, handler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebServer(InetAddress bindAddress, int port, int maxConnections, HttpRequestHandler handler, boolean verbose) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.maxConnections = maxConnections;
|
this.maxConnections = maxConnections;
|
||||||
this.bindAdress = bindAdress;
|
this.bindAddress = bindAddress;
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
|
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
|
||||||
@ -68,7 +72,7 @@ public synchronized void start() {
|
|||||||
connectionThreads.allowCoreThreadTimeOut(true);
|
connectionThreads.allowCoreThreadTimeOut(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server = new ServerSocket(port, maxConnections, bindAdress);
|
server = new ServerSocket(port, maxConnections, bindAddress);
|
||||||
server.setSoTimeout(0);
|
server.setSoTimeout(0);
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
Logger.global.logError("Error while starting the WebServer!", e);
|
Logger.global.logError("Error while starting the WebServer!", e);
|
||||||
|
@ -224,9 +224,9 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc
|
|||||||
HttpRequestHandler requestHandler = new FileRequestHandler(config.getWebRoot().toPath(), "BlueMap v" + BlueMap.VERSION);
|
HttpRequestHandler requestHandler = new FileRequestHandler(config.getWebRoot().toPath(), "BlueMap v" + BlueMap.VERSION);
|
||||||
|
|
||||||
WebServer webServer = new WebServer(
|
WebServer webServer = new WebServer(
|
||||||
|
config.getWebserverBindAddress(),
|
||||||
config.getWebserverPort(),
|
config.getWebserverPort(),
|
||||||
config.getWebserverMaxConnections(),
|
config.getWebserverMaxConnections(),
|
||||||
config.getWebserverBindAddress(),
|
|
||||||
requestHandler,
|
requestHandler,
|
||||||
verbose
|
verbose
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user