Refactoring

This commit is contained in:
Manuel Friedli 2023-04-02 20:18:21 +02:00
parent dd571a190a
commit 17afb42715
Signed by: manuel
GPG key ID: 41D08ABA75634DA1
2 changed files with 3 additions and 17 deletions

View file

@ -25,14 +25,8 @@ public class LabyrinthServer {
@NonNull @NonNull
private final Undertow undertow; private final Undertow undertow;
public static Option<LabyrinthServer> createAndStartServer() { public static Try<LabyrinthServer> createAndStartServer() {
final Option<LabyrinthServer> serverOption = Try.of(ServerConfig::init) final Try<LabyrinthServer> serverOption = Try.of(ServerConfig::init).mapTry(LabyrinthServer::new);
.mapTry(LabyrinthServer::new)
.onFailure(cause -> log.error(
"Failed to create LabyrinthServer.",
cause
))
.toOption();
serverOption.forEach(LabyrinthServer::start); serverOption.forEach(LabyrinthServer::start);
return serverOption; return serverOption;
} }

View file

@ -5,14 +5,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
LabyrinthServer.createAndStartServer().onEmpty(() -> log.error("Failed to create server. Stopping.")); LabyrinthServer.createAndStartServer().onFailure(e -> log.error("Failed to create server. Stopping.", e));
// 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();
} }
} }