CoralReactor HTTP Server for Vert.x Comparison. Please refer to the article for additional details.
package com.coralblocks.coralreactor.client.bench.client; import java.nio.ByteBuffer; import com.coralblocks.coralbits.util.ByteBufferUtils; import com.coralblocks.coralreactor.client.Client; import com.coralblocks.coralreactor.nio.NioReactor; import com.coralblocks.coralreactor.server.http.HttpServer; import com.coralblocks.coralreactor.util.Configuration; import com.coralblocks.coralreactor.util.MapConfiguration; public class PlaintextHttpServer extends HttpServer { private static final String MESSAGE = "Hello, world!"; private static final String NOT_FOUND = "<h3>Not Found</h3>"; private final StringBuilder sb = new StringBuilder(1024); public PlaintextHttpServer(NioReactor nio, int port, Configuration config) { super(nio, port, config); } @Override protected void handleMessage(Client client, ByteBuffer msg) { HttpAttachment a = (HttpAttachment) getAttachment(client); ByteBuffer req = a.getRequest(); if (ByteBufferUtils.contains(req, "/plaintext ")) { sb.setLength(0); sb.append("HTTP/1.1 200 OK\n"); sb.append("Content-Type: text/plain\n"); sb.append("Server: CoralReactor\n"); sb.append("Date: ").append(getDateTime()).append("\n"); sb.append("Content-length: ").append(MESSAGE.length()).append("\n"); sb.append("\n"); sb.append(MESSAGE); client.send(sb); } else { sb.setLength(0); sb.append("HTTP/1.1 404 Not Found\n"); sb.append("Content-Type: text/html\n"); sb.append("Server: CoralReactor\n"); sb.append("Date: ").append(getDateTime()).append("\n"); sb.append("Content-length: ").append(NOT_FOUND.length()).append("\n"); sb.append("\n"); sb.append(NOT_FOUND); client.send(sb); client.close(); } } public static void main(String[] args) { NioReactor nio = NioReactor.create(); int port = Integer.parseInt(args[0]); MapConfiguration config = new MapConfiguration(); PlaintextHttpServer server = new PlaintextHttpServer(nio, port, config); server.open(); nio.start(); } }