Last active
December 13, 2015 20:38
-
-
Save patriknw/4970807 to your computer and use it in GitHub Desktop.
Spotlight cluster singleton proxy
This file contains 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
class MasterProxy extends Actor { | |
// subscribe to LeaderChanged, re-subscribe when restart | |
override def preStart(): Unit = | |
Cluster(context.system).subscribe(self, classOf[LeaderChanged]) | |
override def postStop(): Unit = | |
Cluster(context.system).unsubscribe(self) | |
var leaderAddress: Option[Address] = None | |
def receive = { | |
case state: CurrentClusterState => leaderAddress = state.leader | |
case LeaderChanged(leader) => leaderAddress = leader | |
case other => master foreach { _ forward other } | |
} | |
def master: Option[ActorRef] = | |
leaderAddress map (a ⇒ context.actorFor(RootActorPath(a) / | |
"user" / "singleton" / "master")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment