Skip to content

Instantly share code, notes, and snippets.

@vietj
Created May 11, 2018 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietj/505eb0d5d72a2dcf674f74406be8d513 to your computer and use it in GitHub Desktop.
Save vietj/505eb0d5d72a2dcf674f74406be8d513 to your computer and use it in GitHub Desktop.
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServerResponse;
public class Main {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.createHttpServer().requestHandler(req -> {
req.response().setChunked(true);
req.response().exceptionHandler(err -> {
System.out.println("GOT ERR");
});
writeMsgUntilFull(vertx, req.response(), done -> {
System.out.println("FULL");
});
}).listen(8080, "localhost", ar -> {
HttpClient client = vertx.createHttpClient();
client.getNow(8080, "localhost", "/test", resp -> {
resp.pause();
vertx.setTimer(1000, id -> {
System.out.println("CLOSING");
resp.request().connection().close();
});
});
});
}
private static void writeMsgUntilFull(Vertx vertx, HttpServerResponse resp, Handler<Void> handler) {
if (resp.writeQueueFull()) {
handler.handle(null);
} else {
resp.write(buff);
vertx.runOnContext(v -> {
writeMsgUntilFull(vertx, resp, handler);
});
}
}
static Buffer buff = Buffer.buffer("oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef" +
"oziejfoizejfoizejfoizjefoijzef");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment