Class RoundRobinAddressSelector
- java.lang.Object
-
- org.asynchttpclient.netty.channel.RoundRobinAddressSelector
-
public final class RoundRobinAddressSelector extends Object
Picks, per host and per request, which resolved IP a new connection should target first whenLoadBalance.ROUND_ROBINis enabled.rotate(String, List)returns the resolved addresses re-ordered so that the round-robin-selected address comes first; the remaining addresses follow (in their original order) so the connector can still fail over to them. The order is taken as-is from the resolver and is not re-sorted, so the per-host counter maps consistently to the same address across requests only when the configuredInetNameResolverreturns the addresses in a stable order (seeLoadBalance.ROUND_ROBIN).This class is concerned only with rotation. Deprioritizing addresses whose connection attempts recently failed is handled separately and mode-independently by
FailedIpCooldownHolder, applied on top of the rotation before a connection is opened.Per-host state is held in a bounded map (capped at 4096); at the cap an arbitrary entry is evicted before a new one is added, so memory stays bounded even for clients that touch very many distinct hosts. Dropping a host's state is harmless — its rotation simply restarts at the first resolved address the next time it is seen.
Thread-safe.
-
-
Constructor Summary
Constructors Constructor Description RoundRobinAddressSelector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<InetSocketAddress>rotate(String host, List<InetSocketAddress> resolved)
-
-
-
Method Detail
-
rotate
public List<InetSocketAddress> rotate(String host, List<InetSocketAddress> resolved)
- Parameters:
host- the request's target hostresolved- the resolved socket addresses (size>= 1), in resolver order- Returns:
- the same list instance when there is nothing to rotate (size
<= 1, or the selected index is already first), otherwise a new list whose first element is the round-robin-selected address (otherwise preserving resolver order)
-
-