Skip to content

Instantly share code, notes, and snippets.

@ebarlas
Created July 12, 2022 15:54
Show Gist options
  • Save ebarlas/c0c33e2bed17009dfe4bcec5d3a06e05 to your computer and use it in GitHub Desktop.
Save ebarlas/c0c33e2bed17009dfe4bcec5d3a06e05 to your computer and use it in GitHub Desktop.
package org.microhttp;
import java.io.IOException;
import java.util.List;
public class ThroughputServer {
public static void main(String[] args) throws IOException {
Response response = new Response(
200,
"OK",
List.of(new Header("Content-Type", "text/plain")),
"hello world\n".getBytes());
Options options = new Options()
.withHost("0.0.0.0")
.withConcurrency(args.length > 1 ? Integer.parseInt(args[1]) : Runtime.getRuntime().availableProcessors());
Logger logger = new NoOpLogger();
EventLoop eventLoop = new EventLoop(options, logger, (req, callback) -> callback.accept(response));
eventLoop.start();
}
static class NoOpLogger implements Logger {
@Override
public boolean enabled() {
return false;
}
@Override
public void log(LogEntry... entries) {
}
@Override
public void log(Exception e, LogEntry... entries) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment