September 2019
Intermediate to advanced
816 pages
18h 47m
English
User problem: Fetch a printer IP via the printing service or fallback to the backup printer IP. Or, generally speaking, when this stage completes exceptionally, it should be composed using the results of the supplied function applied to this stage's exception.
We have CompletableFuture that fetches an IP of a printer managed by the printing service. If the service is not responding then it throws an exception as follows:
CompletableFuture<String> cfServicePrinterIp = CompletableFuture.supplyAsync(() -> { int surrogate = new Random().nextInt(1000); if (surrogate < 500) { throw new IllegalStateException( "Printing service is not responding"); } return "192.168.1.0";});
We also have CompletableFuture that fetches ...