mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-25 12:05:13 +01:00
Remove uneccesary lock, fix double server header, organize packages and class-names
This commit is contained in:
parent
0123041925
commit
892506f2f9
@ -38,6 +38,7 @@
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.common.web.*;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpServer;
|
||||
import de.bluecolored.bluemap.core.debug.StateDumper;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.map.BmMap;
|
||||
@ -81,7 +82,7 @@ public class Plugin implements ServerEventListener {
|
||||
private Map<String, BmMap> maps;
|
||||
|
||||
private RenderManager renderManager;
|
||||
private WebServer webServer;
|
||||
private HttpServer webServer;
|
||||
|
||||
private BlueMapAPIImpl api;
|
||||
|
||||
@ -192,7 +193,7 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
|
||||
}
|
||||
|
||||
try {
|
||||
webServer = new WebServer(routingRequestHandler);
|
||||
webServer = new HttpServer(routingRequestHandler);
|
||||
webServer.bind(new InetSocketAddress(
|
||||
webserverConfig.resolveIp(),
|
||||
webserverConfig.getPort()
|
||||
@ -581,7 +582,7 @@ public RenderManager getRenderManager() {
|
||||
return renderManager;
|
||||
}
|
||||
|
||||
public WebServer getWebServer() {
|
||||
public HttpServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpResponse;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpStatusCode;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -43,7 +42,6 @@ public JsonDataRequestHandler(Supplier<String> dataSupplier) {
|
||||
@Override
|
||||
public HttpResponse handle(HttpRequest request) {
|
||||
HttpResponse response = new HttpResponse(HttpStatusCode.OK);
|
||||
response.addHeader("Server", "BlueMap v" + BlueMap.VERSION);
|
||||
response.addHeader("Cache-Control", "no-cache");
|
||||
response.addHeader("Content-Type", "application/json");
|
||||
response.setData(dataSupplier.get());
|
||||
|
@ -1,23 +0,0 @@
|
||||
package de.bluecolored.bluemap.common.web;
|
||||
|
||||
import de.bluecolored.bluemap.common.web.http.HttpConnection;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.SelectionConsumer;
|
||||
import de.bluecolored.bluemap.common.web.http.Server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WebServer extends Server {
|
||||
|
||||
private final HttpRequestHandler requestHandler;
|
||||
|
||||
public WebServer(HttpRequestHandler requestHandler) throws IOException {
|
||||
this.requestHandler = requestHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectionConsumer createConnectionHandler() {
|
||||
return new HttpConnection(requestHandler);
|
||||
}
|
||||
|
||||
}
|
@ -9,11 +9,9 @@
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class HttpConnection implements SelectionConsumer {
|
||||
|
||||
private final ReentrantLock processingLock = new ReentrantLock();
|
||||
private final HttpRequestHandler requestHandler;
|
||||
private HttpRequest request;
|
||||
private HttpResponse response;
|
||||
@ -25,9 +23,7 @@ public HttpConnection(HttpRequestHandler requestHandler) {
|
||||
@Override
|
||||
public void accept(SelectionKey selectionKey) {
|
||||
if (!selectionKey.isValid()) return;
|
||||
if (!processingLock.tryLock()) return;
|
||||
|
||||
try {
|
||||
SelectableChannel selChannel = selectionKey.channel();
|
||||
|
||||
if (!(selChannel instanceof SocketChannel)) return;
|
||||
@ -78,10 +74,6 @@ public void accept(SelectionKey selectionKey) {
|
||||
Logger.global.logWarning("Failed to close channel" + e2);
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
processingLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package de.bluecolored.bluemap.common.web.http;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HttpServer extends Server {
|
||||
|
||||
private final HttpRequestHandler requestHandler;
|
||||
|
||||
public HttpServer(HttpRequestHandler requestHandler) throws IOException {
|
||||
this.requestHandler = requestHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectionConsumer createConnectionHandler() {
|
||||
return new HttpConnection(requestHandler);
|
||||
}
|
||||
|
||||
}
|
@ -40,6 +40,7 @@
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.common.web.*;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpServer;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.logger.LoggerLogger;
|
||||
@ -202,7 +203,7 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc
|
||||
HttpRequestHandler handler = new BlueMapResponseModifier(routingRequestHandler);
|
||||
if (verbose) handler = new LoggingRequestHandler(handler);
|
||||
|
||||
WebServer webServer = new WebServer(handler);
|
||||
HttpServer webServer = new HttpServer(handler);
|
||||
webServer.bind(new InetSocketAddress(
|
||||
config.resolveIp(),
|
||||
config.getPort()
|
||||
|
Loading…
Reference in New Issue
Block a user