Package org.apache.zookeeper.client
Interface HostProvider
-
- All Known Implementing Classes:
StaticHostProvider
@Public public interface HostProvider
A set of hosts a ZooKeeper client should connect to. Classes implementing this interface must guarantee the following: * Every call to next() returns an InetSocketAddress. So the iterator never ends. * The size() of a HostProvider may never be zero. A HostProvider must return resolved InetSocketAddress instances on next() if the next address is resolvable. In that case, it's up to the HostProvider, whether it returns the next resolvable address in the list or return the next one as UnResolved. Different HostProvider could be imagined: * A HostProvider that loads the list of Hosts from an URL or from DNS * A HostProvider that re-resolves the InetSocketAddress after a timeout. * A HostProvider that prefers nearby hosts.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description InetSocketAddress
next(long spinDelay)
The next host to try to connect to.void
onConnected()
Notify the HostProvider of a successful connection.int
size()
boolean
updateServerList(Collection<InetSocketAddress> serverAddresses, InetSocketAddress currentHost)
Update the list of servers.
-
-
-
Method Detail
-
size
int size()
-
next
InetSocketAddress next(long spinDelay)
The next host to try to connect to. For a spinDelay of 0 there should be no wait.- Parameters:
spinDelay
- Milliseconds to wait if all hosts have been tried once.
-
onConnected
void onConnected()
Notify the HostProvider of a successful connection. The HostProvider may use this notification to reset it's inner state.
-
updateServerList
boolean updateServerList(Collection<InetSocketAddress> serverAddresses, InetSocketAddress currentHost)
Update the list of servers. This returns true if changing connections is necessary for load-balancing, false otherwise.- Parameters:
serverAddresses
- new host listcurrentHost
- the host to which this client is currently connected- Returns:
- true if changing connections is necessary for load-balancing, false otherwise
-
-