CachedDNSToSwitchMapping (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.net, class: CachedDNSToSwitchMapping

Package org.apache.hadoop.net

# Class CachedDNSToSwitchMapping

java.lang.Object
org.apache.hadoop.net.AbstractDNSToSwitchMapping
org.apache.hadoop.net.CachedDNSToSwitchMapping

All Implemented Interfaces:
  `Configurable`, `DNSToSwitchMapping`

Direct Known Subclasses:
  `ScriptBasedMapping`, `TableMapping`

@Public @Evolving public class CachedDNSToSwitchMapping extends AbstractDNSToSwitchMapping
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
  Modifier and Type
  Field
  Description
  `protected final DNSToSwitchMapping`
  `rawMapping`
  The uncached mapping

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CachedDNSToSwitchMapping(DNSToSwitchMapping rawMapping)`
  cache a raw DNS mapping

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Map<String,String>`
  `getSwitchMap()`
  Get the (host x switch) map.
  `boolean`
  `isSingleSwitch()`
  Delegate the switch topology query to the raw mapping, via `AbstractDNSToSwitchMapping.isMappingSingleSwitch(DNSToSwitchMapping)`
  `void`
  `reloadCachedMappings()`
  Reload all of the cached mappings.
  `void`
  `reloadCachedMappings(List<String> names)`
  Reload cached mappings on specific nodes.
  `List<String>`
  `resolve(List<String> names)`
  Resolves a list of DNS-names/IP-addresses and returns back a list of switch information (network paths).
  `String`
  `toString()`

  ### Methods inherited from class org.apache.hadoop.net.AbstractDNSToSwitchMapping

  `dumpTopology, getConf, isMappingSingleSwitch, isSingleSwitchByScriptPolicy, setConf`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### rawMapping

    protected final DNSToSwitchMapping rawMapping
    The uncached mapping

- ## Constructor Details

  - ### CachedDNSToSwitchMapping

    public CachedDNSToSwitchMapping(DNSToSwitchMapping rawMapping)
    cache a raw DNS mapping
    Parameters:
      `rawMapping` - the raw mapping to cache

- ## Method Details

  - ### resolve

    public List<String> resolve(List<String> names)
    Description copied from interface: `DNSToSwitchMapping`
    Resolves 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_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

    public Map<String,String> getSwitchMap()
    Get the (host x switch) map.
    Overrides:
      `getSwitchMap` in class `AbstractDNSToSwitchMapping`
    Returns:
      a copy of the cached map of hosts to rack

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### isSingleSwitch

    public boolean isSingleSwitch()
    Delegate the switch topology query to the raw mapping, via `AbstractDNSToSwitchMapping.isMappingSingleSwitch(DNSToSwitchMapping)`
    Overrides:
      `isSingleSwitch` in class `AbstractDNSToSwitchMapping`
    Returns:
      true iff the raw mapper is considered single-switch.

  - ### reloadCachedMappings

    public void reloadCachedMappings()
    Description copied from interface: `DNSToSwitchMapping`
    Reload 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.

  - ### reloadCachedMappings

    public void reloadCachedMappings(List<String> names)
    Description copied from interface: `DNSToSwitchMapping`
    Reload cached mappings on specific nodes. If there is a cache on these nodes, this method will clear it, so that future accesses will see updated data.
    Parameters:
      `names` - input names.