Skip to content

Instantly share code, notes, and snippets.

@sam
Last active September 28, 2015 18:22
Show Gist options
  • Save sam/7b317a097485c38b5206 to your computer and use it in GitHub Desktop.
Save sam/7b317a097485c38b5206 to your computer and use it in GitHub Desktop.
class Job extends Actor {
def receive = idle
def idle: Receive = {
case Parse(_uri) =>
uri = _uri
requestor = context.sender()
sources ! Open(_uri)
context become parsing
}
def parsing: Receive = {
case Opened(PathU("EN" :: "NEWSRELEASES" :: _), Content(content)) =>
done()
case Opened(uri @ PathU("EN" :: Nil), Breadcrumb(breadcrumbs)) =>
breadcrumbs foreach(context.self ! uri / _)
done()
case Opened(_, Content(content)) =>
requestor ! Job.Unhandled(uri, content, "Parser unspecified")
done()
case Opened(_, nodes) =>
requestor ! Job.Unhandled(uri, nodes, "No mainContent section available")
done()
}
def collectWork: Receive = {
case Terminated(job) =>
// re-queue for a doneCheck since I've seen comments that Terminated can jump the mailbox.
// Doesn't seem likely, but doesn't hurt to be safe.
context.self ! Done
case Done =>
if(context.children.isEmpty) {
// No child actors.
requestor ! Done
context.self ! PoisonPill
}
}
def done(): Unit = {
context become collectWork
context.self ! Done
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment