1 2 3 4 5 6 7 8 9 10 11 12 | public class BlockingGet { public static void main(String[] args) throws Exception { RatpackServer.start(server -> server.handlers(chain -> chain.get(ctx -> Blocking.get(() -> { Thread.sleep(5000); return "Hello World"; }).then(str -> ctx.render(str))) ) ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class FileWriter { public static void main(String[] args) throws Exception { RxRatpack.initialize(); new FileWriter().start(); } public void start() throws Exception { RatpackServer.start(server -> server .serverConfig(c -> c.baseDir(Paths.get("app").toAbsolutePath())) .handlers(chain -> chain.get(ctx -> { Publisher<String> publisher = RxReactiveStreams.toPublisher( Observable.from( Files.readAllLines( ctx.getFileSystemBinding().file("largefile.txt")))); ctx.render(stringChunks(publisher)); }) ) ); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |