“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.

Author: Akinora Sharamar
Country: Burundi
Language: English (Spanish)
Genre: Software
Published (Last): 18 October 2004
Pages: 32
PDF File Size: 20.58 Mb
ePub File Size: 16.18 Mb
ISBN: 978-4-47279-723-1
Downloads: 67146
Price: Free* [*Free Regsitration Required]
Uploader: Mikagami

The value of an Akka Future will normally become available sometime after creation, or it may incorporate an exception raised during computation. CompletionStage also has async methods which take Executor as a second parameter, just like Future:.

You should either be familiar with programming using Java generics or some Scala before reading this book.

A common use case within Akka is to have some computation performed concurrently without needing the extra utility of an Actor AbstractActor. The blocking operations are located in Composabke. When non-async methods are applied on a not yet completed CompletionStagethey are completed by the thread which completes initial CompletionStage:. Handling Exception s will be discussed further within this documentation.

The source code for this page can be found here. Akka futures has a Java API, and it provides Java programs with almost every bit of the same futures capability available to Scala programs.


Composable Futures with Akka

The futures implementation provided by Akka 1. Instead, the flatMap method should be used:. Non-async methods When non-async methods are applied on a not yet completed CompletionStagethey are completed by the thread which completes compisable CompletionStage: Here we wait for the results from the first 2 Actor s before sending that result to the third Actor.

Akka Futures can also be preset to a value or exception when created. Something to note when using these methods: You can also use the SBT console to try code snippets interactively.

When in doubt, async methods with explicit executor should be used. Java and Scala can both use Akka Futures The futures implementation bundled in the free, open source Akka stack is written in Scala. When our original Futuref1completes, it will also apply our function and complete the compisable Future with its result.

witg If you need to do conditional propagation, you can use filter: He is often engaged to turn around projects and can provide interim technical leadership for companies in transition. As mentioned above, default async methods are always executed on ForkJoinPool.

When using non-blocking it is better to use the mapTo method to safely try to cast a Future to an expected type:. Actors are generally preferred for coordinated or stateful activities.


Mike Slinn – Connoisseur of Technology: Composable Futures with Akka

In this example we are joining two strings together within a Future. Here we have 2 actors processing a single message each. To wait for and retrieve the actual result the simplest method is:. The implementation extends standard Java CompletableFuture.

For example, transformations and operations on collections of futures are supported, along with numerous asynchronous callbacks.

Composable Futures with Akka 2.0

After adding any additional computation stage to CompletionStage returned by scala-java8-compat e. Multicore concurrency requires multi-threaded programming, but that is hard to do properly. The sequence and traverse helper methods can make it easier to handle more complex use cases.

Existing projects can use this technique to rapidly leverage the extra functionality of Akka futures, futufes thereby extend the functionality of legacy software.

About Contents Change history No longer available. It is also possible to handle an Exception by returning a different result. The completion is delayed: