public class DnsSrvConnectionStrategy extends Object implements ConnectionStrategy
Modifier and Type | Class and Description |
---|---|
protected static class |
DnsSrvConnectionStrategy.SrvRecord
SRV record.
|
Modifier and Type | Field and Description |
---|---|
private static long |
DEFAULT_TTL
Default time to live for DNS results.
|
private static String |
DNS_CONTEXT_FACTORY
JNDI context factory for DNS.
|
private static String |
DNS_PROVIDER_URL
JNDI context factory for DNS.
|
private Map<String,Object> |
jndiEnv
JNDI environment.
|
protected Logger |
logger
Logger for this class.
|
private List<DnsSrvConnectionStrategy.SrvRecord> |
srvRecords
SRV records from the last DNS lookup.
|
private long |
srvTtl
Time to live for SRV records in milliseconds.
|
Constructor and Description |
---|
DnsSrvConnectionStrategy()
Creates a new DNS SRV connection strategy.
|
DnsSrvConnectionStrategy(long ttl)
Creates a new DNS SRV connection strategy.
|
DnsSrvConnectionStrategy(Map<String,Object> env,
long ttl)
Creates a new DNS SRV connection strategy.
|
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
getJndiEnvironment()
Returns the JNDI environment used for DNS lookup.
|
String[] |
getLdapUrls(ConnectionFactoryMetadata metadata)
Returns a list of URLs retrieved from DNS SRV records.
|
long |
getTimeToLive()
Returns the time that DNS lookups will be cached.
|
protected List<DnsSrvConnectionStrategy.SrvRecord> |
retrieveDNSRecords(String name,
Map<String,Object> props,
long ttl)
Uses JNDI to retrieve the DNS SRV record from the supplied url.
|
void |
setJndiEnvironment(Map<String,Object> env)
Sets the JNDI environment used for DNS lookups.
|
void |
setTimeToLive(long ttl)
Sets the time that DNS lookups will be cached.
|
protected List<DnsSrvConnectionStrategy.SrvRecord> |
sortSrvRecords(List<DnsSrvConnectionStrategy.SrvRecord> records)
Sorts the supplied SRV records according to RFC 2782.
|
String |
toString() |
private static final String DNS_CONTEXT_FACTORY
private static final String DNS_PROVIDER_URL
private static final long DEFAULT_TTL
protected final Logger logger
private long srvTtl
private List<DnsSrvConnectionStrategy.SrvRecord> srvRecords
public DnsSrvConnectionStrategy()
public DnsSrvConnectionStrategy(long ttl)
ttl
- time to live in milliseconds for SRV recordspublic Map<String,Object> getJndiEnvironment()
public long getTimeToLive()
public void setJndiEnvironment(Map<String,Object> env)
Context.INITIAL_CONTEXT_FACTORY
is set, it is
defaulted to DNS_CONTEXT_FACTORY
. If no Context.PROVIDER_URL
is set, it is defaulted to DNS_PROVIDER_URL
.env
- jndi environment or nullpublic void setTimeToLive(long ttl)
ttl
- time to live in millisecondspublic String[] getLdapUrls(ConnectionFactoryMetadata metadata)
getLdapUrls
in interface ConnectionStrategy
metadata
- which can be used to produce the URL listprotected List<DnsSrvConnectionStrategy.SrvRecord> retrieveDNSRecords(String name, Map<String,Object> props, long ttl) throws NamingException
name
- of the SRV recordsprops
- for the JNDI contextttl
- time to live for each SRV recordNamingException
- if the DNS record cannot be retrievedprotected List<DnsSrvConnectionStrategy.SrvRecord> sortSrvRecords(List<DnsSrvConnectionStrategy.SrvRecord> records)
records
- to sortCopyright © 2003-2019 Virginia Tech. All Rights Reserved.