Class DnsIntentRegistry

java.lang.Object
org.mockserver.mock.dns.DnsIntentRegistry

public class DnsIntentRegistry extends Object
Thread-safe bounded registry that records the hostname-to-IP answers MockServer's DNS server has handed out. When MockServer's DNS server responds with an A or AAAA record mapping a queried hostname to an IP address, that mapping is recorded here (answeredIP -> queriedHostname).

The DNS-intent transparent-proxy resolver (DnsIntentOriginalDestinationResolver) consumes this registry to recover the intended hostname for a connection that arrived at a given IP — enabling expectation matching and forwarding by host even when the client connected by IP because MockServer's DNS pointed the name at that IP.

Oldest-inserted entries are evicted (insertion-order / FIFO, not access-order LRU) when the registry reaches its maximum capacity; reads (recover(java.net.InetAddress)) stay fully concurrent. If the same IP is answered for a different hostname the most-recent answer wins (the value is updated in place without changing eviction order).

  • Constructor Details

    • DnsIntentRegistry

      public DnsIntentRegistry(int maxSize)
  • Method Details

    • getInstance

      public static DnsIntentRegistry getInstance()
    • record

      public void record(InetAddress answeredIp, String hostname)
      Records that MockServer's DNS server answered with the given IP for the given hostname. Trailing dots are stripped from DNS qnames (e.g. "host.example.com." becomes "host.example.com").
      Parameters:
      answeredIp - the IP address from an A or AAAA answer record
      hostname - the queried DNS name
    • recover

      public String recover(InetAddress connectedIp)
      Recovers the hostname that MockServer's DNS server mapped to the given IP address.
      Parameters:
      connectedIp - the IP address the client connected to
      Returns:
      the hostname, or null if no mapping is known
    • clear

      public void clear()
    • size

      public int size()
      Returns the number of entries currently stored (useful for testing).