Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Messages {
- case class Process(epub: File, isbn: String, processFun: (Elem, String) => Unit)
- case object Fin
- }
- class FixedNumberOfChildren(maxChildren: Int) extends Actor {
- var numChildren: Int = 0
- override def receive: Receive = {
- case m:ProcessEpub =>
- if (numChildren >= maxChildren)
- self ! m
- else {
- val child = context.actorOf(Props(classOf[EpubProcessorActor]))
- context.watch(child)
- numChildren += 1
- child ! m
- }
- case Terminated(_) =>
- numChildren -= 1
- case Fin =>
- context.system.shutdown()
- }
- }
- class ProcessorActor extends Actor with StrictLogging {
- def toXml(stream: Stream[Update], isbn: String): Elem = {...}
- override def receive: Actor.Receive = {
- case Process(epub, isbn, f) =>
- val updates = {epub, isbn => stream[Update]}
- val xml = toXml(updates, isbn)
- f(xml, isbn)
- self ! PoisonPill
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement