From 17afb42715c639d0cbdb8d72849a6a5a6638036f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sun, 2 Apr 2023 20:18:21 +0200 Subject: [PATCH] Refactoring --- .../ch/fritteli/labyrinth/server/LabyrinthServer.java | 10 ++-------- src/main/java/ch/fritteli/labyrinth/server/Main.java | 10 +--------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/fritteli/labyrinth/server/LabyrinthServer.java b/src/main/java/ch/fritteli/labyrinth/server/LabyrinthServer.java index f6cdbd0..caa07b9 100644 --- a/src/main/java/ch/fritteli/labyrinth/server/LabyrinthServer.java +++ b/src/main/java/ch/fritteli/labyrinth/server/LabyrinthServer.java @@ -25,14 +25,8 @@ public class LabyrinthServer { @NonNull private final Undertow undertow; - public static Option createAndStartServer() { - final Option serverOption = Try.of(ServerConfig::init) - .mapTry(LabyrinthServer::new) - .onFailure(cause -> log.error( - "Failed to create LabyrinthServer.", - cause - )) - .toOption(); + public static Try createAndStartServer() { + final Try serverOption = Try.of(ServerConfig::init).mapTry(LabyrinthServer::new); serverOption.forEach(LabyrinthServer::start); return serverOption; } diff --git a/src/main/java/ch/fritteli/labyrinth/server/Main.java b/src/main/java/ch/fritteli/labyrinth/server/Main.java index e11f627..fbdc645 100644 --- a/src/main/java/ch/fritteli/labyrinth/server/Main.java +++ b/src/main/java/ch/fritteli/labyrinth/server/Main.java @@ -5,14 +5,6 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class Main { public static void main(String[] args) { - LabyrinthServer.createAndStartServer().onEmpty(() -> log.error("Failed to create server. Stopping.")); - -// final ServerConfig config = ServerConfig.init(); -// log.info("Starting Server at http://{}:{}/", config.getAddress().getHostAddress(), config.getPort()); -// Undertow.builder() -// .addHttpListener(config.getPort(), config.getAddress().getHostAddress()) -// .setHandler(UndertowPlayground.r) -// .build() -// .start(); + LabyrinthServer.createAndStartServer().onFailure(e -> log.error("Failed to create server. Stopping.", e)); } }