Package org.apache.zookeeper.client
Class StaticHostProvider
- java.lang.Object
-
- org.apache.zookeeper.client.StaticHostProvider
-
- All Implemented Interfaces:
HostProvider
@Public public final class StaticHostProvider extends java.lang.Object implements HostProvider
Most simple HostProvider, resolves on every next() call. Please be aware that although this class doesn't do any DNS caching, there're multiple levels of caching already present across the stack like in JVM, OS level, hardware, etc. The best we could do here is to get the most recent address from the underlying system which is considered up-to-date.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStaticHostProvider.Resolver
-
Constructor Summary
Constructors Constructor Description StaticHostProvider(java.util.Collection<java.net.InetSocketAddress> serverAddresses)Constructs a SimpleHostSet.StaticHostProvider(java.util.Collection<java.net.InetSocketAddress> serverAddresses, StaticHostProvider.Resolver resolver)Introduced for testing purposes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.InetSocketAddressnext(long spinDelay)The next host to try to connect to.voidonConnected()Notify the HostProvider of a successful connection.intsize()
-
-
-
Constructor Detail
-
StaticHostProvider
public StaticHostProvider(java.util.Collection<java.net.InetSocketAddress> serverAddresses)
Constructs a SimpleHostSet.- Parameters:
serverAddresses- possibly unresolved ZooKeeper server addresses- Throws:
java.lang.IllegalArgumentException- if serverAddresses is empty or resolves to an empty list
-
StaticHostProvider
public StaticHostProvider(java.util.Collection<java.net.InetSocketAddress> serverAddresses, StaticHostProvider.Resolver resolver)Introduced for testing purposes. getAllByName() is a static method of InetAddress, therefore cannot be easily mocked. By abstraction of Resolver interface we can easily inject a mocked implementation in tests.- Parameters:
serverAddresses- possibly unresolved ZooKeeper server addressesresolver- custom resolver implementation- Throws:
java.lang.IllegalArgumentException- if serverAddresses is empty or resolves to an empty list
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceHostProvider
-
next
public java.net.InetSocketAddress next(long spinDelay)
Description copied from interface:HostProviderThe next host to try to connect to. For a spinDelay of 0 there should be no wait.- Specified by:
nextin interfaceHostProvider- Parameters:
spinDelay- Milliseconds to wait if all hosts have been tried once.- Returns:
- The next host to try to connect to with resolved address. If the host is not resolvable, the unresolved address will be returned.
-
onConnected
public void onConnected()
Description copied from interface:HostProviderNotify the HostProvider of a successful connection. The HostProvider may use this notification to reset it's inner state.- Specified by:
onConnectedin interfaceHostProvider
-
-