Hey,
I'm currently programming a room service application which gets a room actor reference from a map (given an id) or creates a new room actor if there is no reference existent. Right now, it works fine because there is only one service. Nevertheless, I want to create a cluster of room services and this is where it begins to get tricky for me.
I want to ensure that there is only one instance of a room among the services.
My first attempt:
(Starting up)
1. When started, it waits for the CurrentClusterState and sends a "register" message to all given nodes.
2. It creates a counter for expected "register" responses to make sure that it doesn't look for existent rooms across the services until it knows about all.
3. After getting all responses, it is ready for "get this room" input.
(Fetching rooms)
4. When it receives a "get room with id 1" message, it looks for an entry in the local map.
5. If it founds one, it's done.
6. If it doesn't find it, it sends a "get room with id 1 or avoid creation of it" message across the cluster (the "avoid creation of it" message is sent in order to avoid that another service creates the same room after it was made sure that the room doesn't exist globally).
7. Now, it waits for all responses. If there is a room, it sends a "make the room creatable again" message to all services and it's done.
8. If it doesn't find it again, it creates the room, adds it to the local map and sends a "make the room creatable again" message to all services.
9. (Sends result to requestor)
In my opinion, this solution is way too complicated and it depends too much on the availability of all nodes.
Thanks!
Cheers,
Steve Winfield