Package org.apache.zookeeper.client
Class DnsSrvHostProvider
java.lang.Object
org.apache.zookeeper.client.DnsSrvHostProvider
- All Implemented Interfaces:
AutoCloseable,HostProvider
DNS SRV-based HostProvider that dynamically resolves host port names from DNS SRV records.
This implementation periodically refreshes the server list by querying DNS SRV records and uses HostConnectionManager for all connection management and reconfiguration logic.
Two-Phase Update Strategy:
- Phase 1 (Background): Timer thread detects DNS changes without caching results
- Phase 2 (Connection-time): Fresh DNS lookup during connect attempt if changes detected
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDnsSrvHostProvider(String dnsSrvName) Constructs a DnsSrvHostProvider with the given DNS nameDnsSrvHostProvider(String dnsSrvName, long randomnessSeed, DnsSrvHostProvider.DnsSrvResolver dnsResolver, ZKClientConfig clientConfig) Constructs a DnsSrvHostProvider with the given DNS name, randomization seed, DNS resolver and ZKClientConfigDnsSrvHostProvider(String dnsSrvName, long randomnessSeed, ZKClientConfig clientConfig) Constructs a DnsSrvHostProvider with the given DNS name, randomness seed and ZKClientConfigDnsSrvHostProvider(String dnsSrvName, ZKClientConfig clientConfig) Constructs a DnsSrvHostProvider with the given DNS name and ZKClientConfig -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the HostProvider and release any resources.next(long spinDelay) The next host to try to connect to.voidNotify the HostProvider of a successful connection.intsize()booleanupdateServerList(Collection<InetSocketAddress> serverAddresses, InetSocketAddress currentHost) Update the list of servers.
-
Constructor Details
-
DnsSrvHostProvider
Constructs a DnsSrvHostProvider with the given DNS name- Parameters:
dnsSrvName- the DNS name to query for SRV records- Throws:
IllegalArgumentException- if dnsSrvName is null or empty or invalid or if no SRV records are found for the DNS name or if DNS lookup fails
-
DnsSrvHostProvider
Constructs a DnsSrvHostProvider with the given DNS name and ZKClientConfig- Parameters:
dnsSrvName- the DNS name to query for SRV recordsclientConfig- ZooKeeper client configuration- Throws:
IllegalArgumentException- if dnsSrvName is null or empty or invalid or if no SRV records are found for the DNS name or if DNS lookup fails
-
DnsSrvHostProvider
Constructs a DnsSrvHostProvider with the given DNS name, randomness seed and ZKClientConfig- Parameters:
dnsSrvName- the DNS name to query for SRV recordsrandomnessSeed- seed for randomizationclientConfig- ZooKeeper client configuration- Throws:
IllegalArgumentException- if dnsSrvName is null or empty or invalid or if no SRV records are found for the DNS name or if DNS lookup fails
-
DnsSrvHostProvider
public DnsSrvHostProvider(String dnsSrvName, long randomnessSeed, DnsSrvHostProvider.DnsSrvResolver dnsResolver, ZKClientConfig clientConfig) Constructs a DnsSrvHostProvider with the given DNS name, randomization seed, DNS resolver and ZKClientConfig- Parameters:
dnsSrvName- the DNS name to query for SRV recordsrandomnessSeed- seed for randomizationdnsResolver- custom DNS resolverclientConfig- ZooKeeper client configuration- Throws:
IllegalArgumentException- if dnsSrvName is null or empty or invalid or if no SRV records are found for the DNS name or if DNS lookup fails
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceHostProvider
-
next
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.
-
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
-
updateServerList
public boolean updateServerList(Collection<InetSocketAddress> serverAddresses, InetSocketAddress currentHost) Description copied from interface:HostProviderUpdate the list of servers. This returns true if changing connections is necessary for load-balancing, false otherwise.- Specified by:
updateServerListin interfaceHostProvider- 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
-
close
public void close()Description copied from interface:HostProviderClose the HostProvider and release any resources. Default implementation does nothing for backward compatibility- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceHostProvider
-