Package org.mockserver.mock.dns
Class DnsIntentRegistry
java.lang.Object
org.mockserver.mock.dns.DnsIntentRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()static DnsIntentRegistryvoidrecord(InetAddress answeredIp, String hostname) Records that MockServer's DNS server answered with the given IP for the given hostname.recover(InetAddress connectedIp) Recovers the hostname that MockServer's DNS server mapped to the given IP address.intsize()Returns the number of entries currently stored (useful for testing).
-
Constructor Details
-
DnsIntentRegistry
public DnsIntentRegistry(int maxSize)
-
-
Method Details
-
getInstance
-
record
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 recordhostname- the queried DNS name
-
recover
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
nullif no mapping is known
-
clear
public void clear() -
size
public int size()Returns the number of entries currently stored (useful for testing).
-