This file contains hidden or 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
vertx.executeBlocking(future -> { | |
//Blocking part | |
future.complete(); | |
} , res -> { | |
if (res.succeeded()) { | |
//Success | |
} else { | |
//Failure | |
} | |
}); |
This file contains hidden or 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
vertx.executeBlocking(future -> { | |
byte[] bytes = parseLargeFile(filename); | |
// Complete the future with the generated objects in the | |
// blocking method | |
future.complete(bytes); | |
} |
This file contains hidden or 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
res -> { | |
if (res.succeeded()) { | |
byte[] bytes = (byte[]) res.result(); | |
response.putHeader("Content-Type", "application/octet-stream"); | |
response.setChunked(true); | |
response.write(Buffer.buffer(bytes)); | |
response.setStatusCode(200); | |
response.end(); | |
} else { | |
response.setStatusCode(500); |
This file contains hidden or 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
// Read file method | |
private Future<String> readFile() { | |
Future<String> future = Future.future(); | |
// Retrieve a FileSystem object from vertx instance and call the | |
// non-blocking readFile method | |
vertx.fileSystem().readFile("src/main/resources/example03/read.txt", handler -> { | |
if (handler.succeeded()) { | |
System.out.println("Read content: " + handler.result()); | |
future.complete("read success"); |
This file contains hidden or 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
// Orchestration based on setHandler | |
private void method1() { | |
// Create first step | |
Future<String> future1 = readFile(); | |
// Set handler on future1 | |
future1.setHandler(res1 -> { | |
if (res1.succeeded()) { | |
Future<String> future2 = writeFile(res1.result()); |
This file contains hidden or 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
Future<String> future1 = readFile(); |
This file contains hidden or 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
future.setHandler(res -> { | |
if (res.succeeded()) { | |
// If the future succeeded | |
Object o = res.result(); | |
// Do something... | |
} else { | |
// If the future failed | |
} | |
} |
This file contains hidden or 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
future.setHandler(res -> { | |
if (res.succeeded()) { | |
// If the future succeeded | |
Object o = res.result(); | |
// Do something... | |
} else { | |
// If the future failed | |
} | |
} |
This file contains hidden or 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
// Orchestration based on compose | |
private void method2() { | |
// Create first step | |
Future<String> future1 = readFile(); | |
// Define future1 composition | |
future1.compose(s1 -> { | |
Future<String> future2 = writeFile(future1.result()); | |
// Define future2 composition |
This file contains hidden or 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
future.compose(res -> { | |
// If the future succeeded | |
Object o = res.result; | |
//Do something | |
}, Future.future().setHandler(handler -> { | |
// If the future failed | |
})); |