Skip to content

Commit 05bacd3

Browse files
committed
refactor(HttpServer): simplify server initialization and cleanup
- Move app initialization into constructor and make field final - Remove redundant null check in unload method
1 parent 7b34041 commit 05bacd3

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/main/java/mindustrytool/handler/HttpServer.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,12 @@
5656
public class HttpServer {
5757
private static final String MAP_PREVIEW_FILE_NAME = "MapPreview";
5858

59-
private Javalin app;
59+
private final Javalin app;
6060

6161
private final ServerController controller;
6262

6363
public HttpServer(ServerController controller) {
6464
this.controller = controller;
65-
Log.info("Http server created: " + this);
66-
}
67-
68-
public void init() {
69-
Log.info("Setup http server");
70-
71-
if (app != null) {
72-
throw new RuntimeException("Already init");
73-
}
7465

7566
app = Javalin.create(config -> {
7667
config.showJavalinBanner = false;
@@ -103,6 +94,12 @@ public void init() {
10394
});
10495
});
10596

97+
Log.info("Http server created: " + this);
98+
}
99+
100+
public void init() {
101+
Log.info("Setup http server");
102+
106103
app.get("stats", context -> {
107104
context.future(() -> {
108105
var future = new CompletableFuture<>();
@@ -624,11 +621,7 @@ public byte[] mapPreview() {
624621
}
625622

626623
public void unload() {
627-
if (app != null) {
628-
app.stop();
629-
app = null;
630-
Log.info("Jetty server stopped");
631-
}
624+
app.stop();
632625
Log.info("Stop http server");
633626
}
634627
}

0 commit comments

Comments
 (0)