“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: Akinozuru Vular
Country: Argentina
Language: English (Spanish)
Genre: Relationship
Published (Last): 20 August 2006
Pages: 468
PDF File Size: 9.31 Mb
ePub File Size: 16.38 Mb
ISBN: 316-1-25022-966-5
Downloads: 16007
Price: Free* [*Free Regsitration Required]
Uploader: Duramar

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

Futures • Akka Documentation

Here we wait for the results from the first 2 Actor s before sending that result to the third Actor. Composable Futures with Akka a,ka. If you need to do conditional propagation, you can use filter: This section explains using plain Scala Futures but focuses on their interop with Akka Actors, so to follow those examples you will want to depend on:.

There are generally two ways of getting a reply from an Actor AbstractActor: The akkka of an Akka Composzble will normally become available sometime after creation, or it may incorporate an exception raised during computation. You can also create already completed Futures using the Future companion Futures classwhich can be either successes:. First thenApply is actually performed on scala-java8-compat instance and computational stage lambda execution is delegated to default Java thenApplyAsync which is executed on ForkJoinPool.

In this example we are joining two strings together within a Future. Existing projects can use this technique to rapidly leverage the extra functionality of Akka futures, and thereby extend the functionality of legacy software. Each actor is configured to be run on a MessageDispatcherand that dispatcher doubles as an ExecutionContext. Special considerations for programming with futures are discussed. Mike Compoxable is a principal at Micronautics Research Corp- orationa contract software development firm that focuses on cutting-edge enterprise software technology.


The futures implementation provided by Akka 1.

Composable Futures with Akka

The scala-java8-compat library returns its own implementation of CompletionStage which delegates all non-async methods to their async counterparts. Since the result of a Future is created concurrently to the rest of the program, exceptions must be handled differently.

For this Future supports onCompleteonSuccess and onFailureof which the last two are specializations of the first. For all other cases, use asynchronous composition as described below.

Instead, the flatMap method should be used:.

You can also combine two Futures into a new Future that will hold a tuple of the compsoable Futures successful results, using the zip operation.

Actors are generally preferred for coordinated or stateful activities.

Akka futures has a Java API, and it provides Java programs with almost every bit of the same futures capability available to Scala programs.

Alternatives to blocking are discussed further within this documentation.

Using pipeTo pipe with the? See also Java 8 Compatibility for Java compatibility. This is done with the recover method. CompletionStage also has async methods which take Executor as a second parameter, just like Future:.

Composable Futures with Akka 2.0

Akka futures integrate easily with existing software projects. Mike has written three books and over fifty articles on software technology. The map method is fine if we are modifying a single Futurebut if 2 or more Future s are involved map will not allow you to combine them together: Actions supplied for dependent completions of non-async methods may be performed by the thread that completes wihh current CompletableFutureor by any other caller of a completion method.

  GE700 PDF

In general, futures are preferred for one-off, uncoordinated, stateless jobs, which can range in duration from a web request of 5ms to data processing jobs of hours or more. Similar programs were written in Java and Scala.

If the sequence passed to fold is empty, it will return the start-value, in the case above, that will be 0. Non-async methods When non-async methods are applied on a not yet completed CompletionStagethey are completed by the thread compowable completes initial CompletionStage: The Akka and Twitter implementations are much more advanced.

He has alka recognized as a software expert in US federal court. He is often engaged to turn around projects and can provide interim technical leadership for companies in transition. Same as with foldthe execution will be composbale asynchronously when the last of the Future is completed, you can also parallelize it by chunking your futures into sub-sequences and reduce them, and then reduce the reduced results again. Blocking is discouraged though as it will cause performance problems.

The Promises chapter in the book includes a case study that shows how easy it is to integrate Akka futures into existing code.

Back To Top