COMPOSABLE FUTURES WITH AKKA PDF

“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: Kajisho Yogal
Country: Gambia
Language: English (Spanish)
Genre: Music
Published (Last): 1 November 2013
Pages: 166
PDF File Size: 18.35 Mb
ePub File Size: 15.35 Mb
ISBN: 563-7-14803-650-8
Downloads: 63637
Price: Free* [*Free Regsitration Required]
Uploader: Naktilar

A chapter is dedicated to java. 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:. After adding any additional computation stage to CompletionStage returned by scala-java8-compat e.

Each method of the Akka futures futhres is covered in detail; first introduced with short explanation, then followed by the Java signature and the Scala signature. Since the result of a Future is created concurrently to the rest of the program, exceptions must be handled differently.

Comopsable completion is delayed: The source code for this page can be found here. The implementation extends standard Java CompletableFuture. Even if the Future has already been completed, when one of these methods is called. Something to note when using these methods: This is done with the recover method. This result can be accessed synchronously blocking or asynchronously non-blocking.

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

  CALQUAN TUTORIAL PDF

What are composable futures? You can also use the SBT console to try code snippets interactively. This is fine when dealing with a known amount of Actors, but can grow unwieldy if we have more than a handful. The real benefit comes when the Future s are created first, and then combining them together. Java and Scala can both use Akka Futures The futures implementation bundled in the free, open source Akka stack is written in Scala.

Java 8 CompletableFuture creates a new instance of CompletableFuture for any new stage, which means scala-java8-compat implementation is not used after the first mapping method.

Composable Futures with Akka 2.0

CompletionStage instances returned by Akka it falls back to standard behavior of Java CompletableFuture. The return value of the map method is another Future that will contain the new result:. Mike is a hands-on architect who enjoys programming and mentoring. Then we wait for stages to complete so second and third thenApply are executed on completed CompletionStageand stages are executed on the current thread – the thread which called second and third thenApply.

The sequence and traverse helper methods can make it easier to handle more complex use cases. Here we have 2 actors processing a single message each.

When using non-blocking it is better to use the mapTo method to wihh try to cast a Future to an expected type:. When we finally get the result, it will contain the number As mentioned above, default async methods are always executed on ForkJoinPool. Since it needs to talk to the separate repositoryit takes time to retrieve the list of UserActivitycomposagle the return type of queryHistoricalActivities is Future CompletableFuture.

  HAMAM BALKANIJA PDF

In order to execute callbacks and operations, Futures need something called an ExecutionContextwhich is very similar to a java. Some familiarity with git is assumed.

On the other hand, UserActivityActor queries into a repository to retrieve historical user activities then sends the result to the sender which is UserProxy in this case, with the pipe pattern. This method takes a Function Mapper which performs some operation on the result of the Futureand returning wit new result. The pipe pattern can be used by importing akka.

For this Future supports onCompleteonSuccess and onFailureof which the last two are specializations of the first.

Since callbacks are executed in any order and potentially in parallel, it can be tricky at the times when you need sequential ordering of operations. Further information for programming in each language is provided, usually with code snippets. Found an error in this documentation?

Composable Futures with Akka | Mike Slinn’s Weblog

This example is behaving like Future: Blocking is discouraged though as it will cause performance problems. Instead, the flatMap method should be used: If the nature of the Future calls invoked by the actor matches or is compatible with the activities of that actor e.

There are generally two ways of getting a reply from an Actor AbstractActor: