concept case in category akka

appears as: case, case, A case, cases, cases
Reactive Design Patterns

This is an excerpt from Manning's book Reactive Design Patterns.

These considerations guide the hierarchical decomposition of Gmail’s overall functionality into smaller and smaller pieces. More precisely, you can apply the Simple Component pattern as described in chapter 12, making sure you clearly delimit and segregate the different responsibilities of the entire application. The Error Kernel pattern and the Let-It-Crash pattern complement this process, ensuring that the application’s architecture is well suited to reliable failure handling—not only in case of machine or network outages, but also for rare failure conditions in the source code that are handled incorrectly (a.k.a. bugs).

Figure 8.1. A sketch of the Saga pattern for moving an email from Alice’s account to Bob’s account, not including the cases for handling timeouts when communicating with the two accounts

Most of the patterns we will encounter are extremely generic, starting with the Request–Response pattern. They can be applied in a variety of cases and come in many forms. The examples are therefore less specific than in other chapters, but we will use the front-end façade of a larger service as a problem setting. You can think of this as a more detailed look at the client interface component of the batch job service, our running example. The particular patterns we will cover are as follows:

Listing 15.18. Implementing the exchange using Actors
case class ChangeBudget(amount: BigDecimal, replyTo: ActorRef) case object ChangeBudgetDone case class CannotChangeBudget(reason: String) class Sam(alice: ActorRef, bob: ActorRef, amount: BigDecimal) extends Actor {   def receive = talkToAlice()   def talkToAlice(): Receive = {     alice ! ChangeBudget(-amount, self)     context.setReceiveTimeout(1.second)     {       case ChangeBudgetDone           => context.become(talkToBob())       case CannotChangeBudget(reason) => context.stop(self)       case ReceiveTimeout             => alice ! ChangeBudget(-amount, self)     }   }   def talkToBob(): Receive = ... #1 } class Alice extends Actor {   var budget: BigDecimal = 10   var alreadyDone: Set[ActorRef] = Set.empty #2   def receive = {     case ChangeBudget(amount, replyTo) if alreadyDone(replyTo) =>       replyTo ! ChangeBudgetDone     case ChangeBudget(amount, replyTo) if amount + budget > 0 =>       budget += amount       alreadyDone += replyTo       context.watch(replyTo)       replyTo ! ChangeBudgetDone     case ChangeBudget(_, replyTo) =>       replyTo ! CannotChangeBudget("insufficient budget")     case Terminated(saga) =>       alreadyDone -= saga   } } #1 - Analog to the previous code #2 - You need to keep track of what has already been done. Here each “Sam” issues only one request (being a Saga).
Akka in Action

This is an excerpt from Manning's book Akka in Action.

Around the year 2005 when Herb Sutter wrote his excellent article, you’d find companies running applications on clustered multiprocessor servers (often no more than two to three, just in case one of them crashed). Support for concurrency in programming languages was available but limited and considered black magic by many mere mortal programmers. Herb Sutter predicted in his article that “programming languages ... will increasingly be forced to deal well with concurrency.”

Listing 2.18. Getting tickets
 case GetTickets(event, tickets) =>      def notFound() = sender() ! TicketSeller.Tickets(event)  #1      def buy(child: ActorRef) =        child.forward(TicketSeller.Buy(tickets))  #2      context.child(event).fold(notFound())(buy) #3 #1 - Sends an empty Tickets message if the ticket seller couldn’t be found #2 - Buys from the found TicketSeller #3 - Executes notFound or buys with the found TicketSeller !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!

Like actors, futures are important asynchronous building blocks that create an opportunity for parallel execution. Both actors and futures are great tools best used for different use cases. It’s a question of the right tool for the right job. We’ll start with describing the type of use case that futures are best suited for, and work through some examples in section 5.1, “Use cases for futures.” Whereas actors provide a mechanism to build a system out of concurrent objects, futures provide a mechanism to build a system out of asynchronous functions.