Our clustered app has a cluster singleton actor that constructs a Cluster
instance, and also subscribes to cluster events.
If you ask it, "What are the current nodes?" it uses cluster.state.members.
I.e., simplified, something like:
val cluster = Cluster(context.system)
override def preStart(): Unit =
cluster.subscribe(self, classOf[MemberEvent])
def receive = {
case state: GetNodes =>
sender ! cluster.state.members
...
}
Currently, we just info-log events like MemberUp, MemberDown, etc.
But I see an Akka activator example for listening to cluster state that
does something like this instead:
val cluster = Cluster(context.system)
var nodes = Set.empty[Member]
override def preStart(): Unit =
cluster.subscribe(self, classOf[MemberEvent])
def receive = {
case MemberUp(member) =>
nodes += member
case MemberRemoved(member, _) =>
nodes -= member case state: GetNodes =>
sender ! nodes
...
}
Is there a reason not to use the Cluster object's mutable state? It seems
to work doing it that way, so I'm wondering whether the activator example
is doing it this way just to illustrate how to handle some MemberEvents, or
whether what our app is doing is incorrect or less reliable in some
circumstances?
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.