Package org.apache.bookkeeper.net
Class CachedDNSToSwitchMapping
java.lang.Object
org.apache.bookkeeper.net.AbstractDNSToSwitchMapping
org.apache.bookkeeper.net.CachedDNSToSwitchMapping
- All Implemented Interfaces:
Configurable,DNSToSwitchMapping
- Direct Known Subclasses:
ScriptBasedMapping
A cached implementation of DNSToSwitchMapping that takes an
raw DNSToSwitchMapping and stores the resolved network location in
a cache. The following calls to a resolved network location
will get its location from the cache.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCachedDNSToSwitchMapping(DNSToSwitchMapping rawMapping) Cache a raw DNS mapping. -
Method Summary
Modifier and TypeMethodDescriptionGet the (host x switch) map.booleanDelegate the switch topology query to the raw mapping, viaAbstractDNSToSwitchMapping.isMappingSingleSwitch(DNSToSwitchMapping).voidReload all of the cached mappings.Resolves a list of DNS-names/IP-addresses and returns back a list of switch information (network paths).toString()booleanHints what to use with implementation when InetSocketAddress is converted to String: hostname (addr.getHostName(), default) or IP address (addr.getAddress().getHostAddress()).Methods inherited from class org.apache.bookkeeper.net.AbstractDNSToSwitchMapping
dumpTopology, getBookieAddressResolver, getConf, isMappingSingleSwitch, isSingleSwitchByScriptPolicy, setBookieAddressResolver, setConf, validateConf
-
Field Details
-
rawMapping
The uncached mapping.
-
-
Constructor Details
-
CachedDNSToSwitchMapping
Cache a raw DNS mapping.- Parameters:
rawMapping- the raw mapping to cache
-
-
Method Details
-
useHostName
public boolean useHostName()Description copied from interface:DNSToSwitchMappingHints what to use with implementation when InetSocketAddress is converted to String: hostname (addr.getHostName(), default) or IP address (addr.getAddress().getHostAddress()).- Returns:
- true if hostname, false if IP address. Default is true.
-
resolve
Description copied from interface:DNSToSwitchMappingResolves a list of DNS-names/IP-addresses and returns back a list of switch information (network paths). One-to-one correspondence must be maintained between the elements in the lists. Consider an element in the argument list - x.y.com. The switch information that is returned must be a network path of the form /foo/rack, where / is the root, and 'foo' is the switch where 'rack' is connected. Note the hostname/ip-address is not part of the returned path. The network topology of the cluster would determine the number of components in the network path.If a name cannot be resolved to a rack, the implementation should return
NetworkTopology.DEFAULT_REGION_AND_RACK. This is what the bundled implementations do, though it is not a formal requirement- Parameters:
names- the list of hosts to resolve (can be empty)- Returns:
- list of resolved network paths. If names is empty, the returned list is also empty
-
getSwitchMap
Get the (host x switch) map.- Overrides:
getSwitchMapin classAbstractDNSToSwitchMapping- Returns:
- a copy of the cached map of hosts to rack
-
toString
-
isSingleSwitch
public boolean isSingleSwitch()Delegate the switch topology query to the raw mapping, viaAbstractDNSToSwitchMapping.isMappingSingleSwitch(DNSToSwitchMapping).- Overrides:
isSingleSwitchin classAbstractDNSToSwitchMapping- Returns:
- true iff the raw mapper is considered single-switch.
-
reloadCachedMappings
public void reloadCachedMappings()Description copied from interface:DNSToSwitchMappingReload all of the cached mappings.If there is a cache, this method will clear it, so that future accesses will get a chance to see the new data.
-