-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LoadBalancer API #77
Comments
Thanks @elandau for creating this issue, we need to nail down the contract :)
Is it true that the Load balancer works on immutable list of instances and for every change the list is swapped with a new list?
Can you explain this more as compared to an Iterable?
This is much like an
I think its true that we will use it with an |
The worst case for the iterator is the scenario where hasNext() returns true but the list is set to empty() before next() is called. next() will end up throwing a NoSuchElementException. To me this sounds like a violation of the contract for iterator. For this to work correctly hasNext() must always return true and we will need to expect a NoSuchElementException from next(). |
We've gone back and forth on various public API options for the load balancer. This issue shall serve as a placeholder for the discussion on which API is the most robust and semantically correct.
Iterator
Getting a client from the load balancer fits naturally with the Iterator interface since it follows the pull model. However, since the load balancer list of hosts may be updated asynchronously the Iterator API can easily be violated. hasNext() may return true but the list may be empty by the time next() is called.
Observable
Implementing the LoadBalancer as an Observable give great flexibility for managing various states and error conditions.
Func0
Using Func0 reduces the API to a simple method call that returns the next client or null if no client is available. Since an Observable must be created to tie the client selection with request execution triggered by a subscription to the Observable we may as well just implement the LoadBalancer as an Observable in the first place.
The text was updated successfully, but these errors were encountered: