Created
October 8, 2012 13:12
-
-
Save patriknw/3852452 to your computer and use it in GitHub Desktop.
Spotlight for Cluster Death Watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case object BackendRegistration | |
case class Job(text: String) | |
class Frontend extends Actor { | |
var backends = IndexedSeq.empty[ActorRef] | |
var jobCounter = 0 | |
def receive = { | |
case job: Job if backends.isEmpty => | |
sender ! "Service unavailable, try again later" | |
case job: Job => | |
jobCounter += 1 | |
backends(jobCounter % backends.size) forward job | |
case BackendRegistration if !backends.contains(sender) => | |
context watch sender | |
backends = backends :+ sender | |
case Terminated(a) ⇒ | |
backends = backends.filterNot(_ == a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
backends = backends.filterNot(_ == a)