Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.94 KB | None | 0 0
  1. object Messages {
  2.   case class Process(epub: File, isbn: String, processFun: (Elem, String) => Unit)
  3.   case object Fin
  4. }
  5.  
  6. class FixedNumberOfChildren(maxChildren: Int) extends Actor {
  7.   var numChildren: Int = 0
  8.   override def receive: Receive = {
  9.     case m:ProcessEpub =>
  10.       if (numChildren >= maxChildren)
  11.         self ! m
  12.       else {
  13.         val child = context.actorOf(Props(classOf[EpubProcessorActor]))
  14.         context.watch(child)
  15.         numChildren += 1
  16.         child ! m
  17.       }
  18.     case Terminated(_) =>
  19.       numChildren -= 1
  20.     case Fin =>
  21.       context.system.shutdown()
  22.   }
  23. }
  24.  
  25. class ProcessorActor extends Actor with StrictLogging {
  26.   def toXml(stream: Stream[Update], isbn: String): Elem = {...}
  27.  
  28.   override def receive: Actor.Receive = {
  29.     case Process(epub, isbn, f) =>
  30.       val updates = {epub, isbn => stream[Update]}
  31.       val xml = toXml(updates, isbn)
  32.       f(xml, isbn)
  33.       self ! PoisonPill
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement