Skip to content

Instantly share code, notes, and snippets.

@helena
Created November 3, 2012 00:30
Show Gist options
  • Save helena/4005230 to your computer and use it in GitHub Desktop.
Save helena/4005230 to your computer and use it in GitHub Desktop.
Akka 2.1 Cluster API
val system = ActorSystem("ClusterSystem")
system.actorOf(Props(new Actor with ActorLogging {
val cluster = Cluster(context.system)
override def preStart(): Unit =
cluster.subscribe(self, classOf[ClusterDomainEvent])
def receive = {
case state: CurrentClusterState =>
log.info("Current members: {}", state.members)
case MemberJoined(member) =>
log.info("Member joined: {}", member)
case MemberUp(member) =>
log.info("Member is Up: {}", member)
case MemberUnreachable(member) =>
log.info("Member detected as unreachable: {}", member)
case MemberDowned(m) =>
log.info("Member detected as downed: {}", member)
case MemberRemoved(m) =>
log.info("Member removed: {}", member)
case _: ClusterDomainEvent => // ignore
}
override def postStop: Unit = cluster unsubscribe self
}), name = "clusterSampleListener")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment