Created
May 11, 2018 16:40
-
-
Save vietj/505eb0d5d72a2dcf674f74406be8d513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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