From 995b7ee53170243d916420a2d8bccd5e3cf6ba4f Mon Sep 17 00:00:00 2001 From: test Date: Fri, 28 Mar 2025 11:57:42 +0200 Subject: [PATCH 1/2] Fixed the EventLoop functions because it used the Java logs handler not the interface) --- src/main/java/module-info.java | 1 + src/main/java/org/microhttp/DebugLogger.java | 2 +- src/main/java/org/microhttp/EventLoop.java | 13 ++++++++----- src/main/java/org/microhttp/Scheduler.java | 3 ++- .../org/microhttp/EventLoopConcurrencyTest.java | 3 ++- .../java/org/microhttp/EventLoopRestartTest.java | 8 ++++---- src/test/java/org/microhttp/TestServer.java | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index eefa788..e87d356 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,3 +1,4 @@ module org.microhttp { + requires java.logging; exports org.microhttp; } diff --git a/src/main/java/org/microhttp/DebugLogger.java b/src/main/java/org/microhttp/DebugLogger.java index b36d12b..344e2d7 100644 --- a/src/main/java/org/microhttp/DebugLogger.java +++ b/src/main/java/org/microhttp/DebugLogger.java @@ -23,7 +23,7 @@ public void log(LogEntry... entries) { @Override public void log(Exception e, LogEntry... entries) { - e.printStackTrace(); + e.getStackTrace(); log(entries); } } diff --git a/src/main/java/org/microhttp/EventLoop.java b/src/main/java/org/microhttp/EventLoop.java index 99a77ac..36934d9 100644 --- a/src/main/java/org/microhttp/EventLoop.java +++ b/src/main/java/org/microhttp/EventLoop.java @@ -15,11 +15,14 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import java.util.logging.Handler; /** * EventLoop is an HTTP server implementation. It provides connection management, network I/O, * request parsing, and request dispatching. */ + + public class EventLoop { private final Options options; @@ -32,14 +35,14 @@ public class EventLoop { private final Thread thread; public EventLoop(Handler handler) throws IOException { - this(Options.builder().build(), handler); + this(Options.builder().build(), (org.microhttp.Handler) handler); } - public EventLoop(Options options, Handler handler) throws IOException { - this(options, NoopLogger.instance(), handler); + public EventLoop(Options options, org.microhttp.Handler handler) throws IOException { + this(options, NoopLogger.instance(), (org.microhttp.Handler) handler); } - public EventLoop(Options options, Logger logger, Handler handler) throws IOException { + public EventLoop(Options options, Logger logger, org.microhttp.Handler handler) throws IOException { this.options = options; this.logger = logger; @@ -49,7 +52,7 @@ public EventLoop(Options options, Logger logger, Handler handler) throws IOExcep AtomicLong connectionCounter = new AtomicLong(); connectionEventLoops = new ArrayList<>(); for (int i = 0; i < options.concurrency(); i++) { - connectionEventLoops.add(new ConnectionEventLoop(options, logger, handler, connectionCounter, stop)); + connectionEventLoops.add(new ConnectionEventLoop(options, logger, (org.microhttp.Handler) handler, connectionCounter, stop)); } thread = new Thread(this::run, "event-loop"); diff --git a/src/main/java/org/microhttp/Scheduler.java b/src/main/java/org/microhttp/Scheduler.java index b2b38d7..71776c8 100644 --- a/src/main/java/org/microhttp/Scheduler.java +++ b/src/main/java/org/microhttp/Scheduler.java @@ -50,7 +50,8 @@ List expired() { return result; } - class Task implements Cancellable { + class Task + implements Cancellable { final Runnable task; final long time; final long id; diff --git a/src/test/java/org/microhttp/EventLoopConcurrencyTest.java b/src/test/java/org/microhttp/EventLoopConcurrencyTest.java index 2d27729..95bd6dc 100644 --- a/src/test/java/org/microhttp/EventLoopConcurrencyTest.java +++ b/src/test/java/org/microhttp/EventLoopConcurrencyTest.java @@ -43,9 +43,10 @@ public static void beforeAll() throws IOException { "OK", List.of(new Header("Content-Type", req.header("Content-Type"))), req.body()); + callback.accept(response); }); - eventLoop = new EventLoop(options, NoopLogger.instance(), handler); + eventLoop = new EventLoop(options, NoopLogger.instance(), (org.microhttp.Handler) handler); eventLoop.start(); port = eventLoop.getPort(); } diff --git a/src/test/java/org/microhttp/EventLoopRestartTest.java b/src/test/java/org/microhttp/EventLoopRestartTest.java index e26c336..0ba1c86 100644 --- a/src/test/java/org/microhttp/EventLoopRestartTest.java +++ b/src/test/java/org/microhttp/EventLoopRestartTest.java @@ -26,7 +26,7 @@ public void stoppingShouldReleasePort() throws IOException, InterruptedException EventLoop secondEventLoop = null; try { - eventLoop = new EventLoop(options, logger, handler); + eventLoop = new EventLoop(options, (Logger) logger, (org.microhttp.Handler) handler); eventLoop.start(); int port = eventLoop.getPort(); eventLoop.stop(); @@ -35,7 +35,7 @@ public void stoppingShouldReleasePort() throws IOException, InterruptedException options = OptionsBuilder.newBuilder() .withPort(port) .build(); - secondEventLoop = new EventLoop(options, logger, handler); + secondEventLoop = new EventLoop(options, (Logger) logger, (org.microhttp.Handler) handler); secondEventLoop.start(); } finally { if (eventLoop != null) { @@ -68,7 +68,7 @@ public void stoppingShouldReleasePortAfterHandledResponse() throws IOException, Collection resourcesToClose = new ArrayList<>(); try { - eventLoop = new EventLoop(options, logger, handler); + eventLoop = new EventLoop(options, (Logger) logger, (org.microhttp.Handler) handler); eventLoop.start(); int port = eventLoop.getPort(); @@ -92,7 +92,7 @@ public void stoppingShouldReleasePortAfterHandledResponse() throws IOException, options = OptionsBuilder.newBuilder() .withPort(port) .build(); - secondEventLoop = new EventLoop(options, logger, handler); + secondEventLoop = new EventLoop(options, (Logger) logger, (org.microhttp.Handler) handler); secondEventLoop.start(); socket = new Socket("localhost", port); diff --git a/src/test/java/org/microhttp/TestServer.java b/src/test/java/org/microhttp/TestServer.java index 0e0e9bd..e8bf517 100644 --- a/src/test/java/org/microhttp/TestServer.java +++ b/src/test/java/org/microhttp/TestServer.java @@ -37,7 +37,7 @@ public class TestServer { .withReadBufferSize(readBufferSize) .withMaxRequestSize(2_048) .build(); - eventLoop = new EventLoop(options, logger, h); + eventLoop = new EventLoop(options, (Logger) logger, (org.microhttp.Handler) h); eventLoop.start(); port = eventLoop.getPort(); } From a2040257a2dd34b8a561aae8b233c794a2aff816 Mon Sep 17 00:00:00 2001 From: test Date: Fri, 28 Mar 2025 11:59:38 +0200 Subject: [PATCH 2/2] ment Changes --- src/main/java/module-info.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index e87d356..eefa788 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,4 +1,3 @@ module org.microhttp { - requires java.logging; exports org.microhttp; }