“Composable Futures with Akka ” features Java and Scala code examples. The book is available in PDF format. Akka is hot, and Akka. Writing concurrent programs that can run in multiple threads and on multiple cores is crucial but daunting. Composable futures provide a convenient abstraction. Composable Futures With Akka is intended for ‘the rest of us’ – Java and Scala programmers who would like to quickly learn how design.
|Published (Last):||7 September 2009|
|PDF File Size:||18.30 Mb|
|ePub File Size:||17.13 Mb|
|Price:||Free* [*Free Regsitration Required]|
Future fallbackTo combines 2 Futures into a new Futureand will hold the successful value of the second Future if the first Future fails. It is very often desirable to be able composablw combine different Futures with each other, below are some examples on how that can be done in a non-blocking fashion. Instead of waiting for this f1 to complete, we apply our function that calculates the length of the string using the map method.
Handling Exception s will be discussed further within this documentation. This book explains how to write concurrent programs that can run in multiple threads and on multiple cores.
Composable Futures with Akka
Found an error in this documentation? For example, transformations and operations on collections of futures are supported, along with numerous asynchronous callbacks. If you find yourself creating a pool of Skka s AbstractActor s for the sole reason of performing a calculation in parallel, there is an easier and faster way:. For these examples PrintResult is defined as follows: Starting with Akka 2. Failure containing the ArithmeticExceptionour Future would have a result of 0.
For this Future supports onCompleteonSuccess and onFailureof which the last two are specializations of the first. Instead, the flatMap method should be used:. CompletionStage also has async methods which take Executor as a second parameter, just like Future:. If you need to do conditional propagation, you can use filter: This result can be accessed synchronously blocking or asynchronously non-blocking.
Composable Futures with Akka 2.0
There are generally two ways of getting a reply from an Composagle AbstractActor: Special considerations for programming with futures are discussed. Composable futures mean that operations on a future or a collection of futures can be chained together without blocking; for compsable, transformations such as map can be applied to a composable future. All async methods without an explicit Executor are performed using the ForkJoinPool.
Existing projects can use this technique to rapidly leverage the extra functionality of Akka futures, and thereby extend the functionality of legacy software. Here we have 2 actors processing a single message each.
Something to note when using these methods: In this example, if the actor replied with a akka. The real benefit comes when the Future s are created first, and then combining them together. He is often engaged to turn around projects and can provide interim technical futuures for companies in transition.
The Akka and Twitter implementations are much more advanced. In the Scala Standard Library, a Future is a data structure used to retrieve the result of some concurrent operation.
Mike Slinn – Connoisseur of Technology: Composable Futures with Akka
When using non-blocking it is better to use the mapTo method to safely try to cast a Future to an expected type:. A common use case within Akka is to have some computation performed concurrently without needing the extra utility of an Actor AbstractActor.
The Promises chapter in the book includes a case study that shows how easy it is to integrate Akka futures into existing code. First thenApply is still executed on ForkJoinPool.
Composable Futures with Akka 2. The sequence and traverse helper methods can make it easier to handle more complex use cases.
You compsoable also use the SBT console to try code snippets interactively. Both blocking and non-blocking operations can be performed on Akka futures. For example, to use traverse to sum the first odd numbers: Non-async methods When non-async methods are applied on a not yet completed CompletionStagethey are completed by the thread which completes initial CompletionStage: