I am trying to understand watches by creating a toy service discover layer in Java. Basic idea is as follow
I have a
Subspace(service, ip), when instances of service come up they will register themselves by doing a set on the subspace
Any process that needs to discover how many instances of a particular service are up and running will put a watch on the service and when watch is trigger do a range query to get all the ips
I am running into following issues when trying to implement this in Java.
It seems like I cannot put watch on parent subspace (example_service in this case). I have to put watch on exact key
In java binding result of the watch in a Future, and watch is trigger when future completes. Which means that I only get notified of the first change on that key. In my usecase I want to get notified everytime a new ip in added under example_service. Not sure if its possible to accomplish that?
Finally, to mimic this example on my laptop I had two different transaction, one starting the watch and second triggering the watch by updating the key. This doesnt seem to work as the future from the watch never completes. Only way i got it to work is when both watch is created and key is updated in the same transaction. How would this work when in real application when watch and update will happen on different machines?