Advertisement
Guest User

Untitled

a guest
Jan 8th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.10 KB | None | 0 0
  1. package org.jamieallen.effectiveakka.pattern.extra
  2.  
  3. import scala.concurrent.ExecutionContext
  4. import scala.concurrent.duration._
  5. import akka.util.Timeout
  6. import org.jamieallen.effectiveakka.common._
  7. import akka.actor.{ Actor, ActorRef }
  8. import akka.pattern.ask
  9.  
  10. class AccountBalanceRetriever1(savingsAccounts: ActorRef, checkingAccounts: ActorRef, moneyMarketAccounts: ActorRef) extends Actor {
  11.   implicit val timeout: Timeout = 100 milliseconds
  12.   implicit val ec: ExecutionContext = context.dispatcher
  13.   def receive = {
  14.     case GetCustomerAccountBalances(id) =>
  15.       val futSavings = savingsAccounts ? GetCustomerAccountBalances(id)
  16.       val futChecking = checkingAccounts ? GetCustomerAccountBalances(id)
  17.       val futMM = moneyMarketAccounts ? GetCustomerAccountBalances(id)
  18.       val futBalances = for {
  19.         savings <- futSavings.mapTo[Option[List[(Long, BigDecimal)]]]
  20.         checking <- futChecking.mapTo[Option[List[(Long, BigDecimal)]]]
  21.         mm <- futMM.mapTo[Option[List[(Long, BigDecimal)]]]
  22.       } yield AccountBalances(savings, checking, mm)
  23.       futBalances map (sender ! _)
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement