Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/microhttp/DebugLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void log(LogEntry... entries) {

@Override
public void log(Exception e, LogEntry... entries) {
e.printStackTrace();
e.getStackTrace();
log(entries);
}
}
13 changes: 8 additions & 5 deletions src/main/java/org/microhttp/EventLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/microhttp/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ List<Runnable> expired() {
return result;
}

class Task implements Cancellable {
class Task
implements Cancellable {
final Runnable task;
final long time;
final long id;
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/microhttp/EventLoopConcurrencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/microhttp/EventLoopRestartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -68,7 +68,7 @@ public void stoppingShouldReleasePortAfterHandledResponse() throws IOException,
Collection<Closeable> 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();

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/microhttp/TestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down