Skip to content

Instantly share code, notes, and snippets.

@patriknw
Created October 8, 2012 13:12
Show Gist options
  • Save patriknw/3852452 to your computer and use it in GitHub Desktop.
Save patriknw/3852452 to your computer and use it in GitHub Desktop.
Spotlight for Cluster Death Watch
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)
}
}
@viktorklang
Copy link

backends = backends.filterNot(_ == a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment