Class RoundRobinAddressFunction

java.lang.Object
com.illumon.iris.db.v2.locations.remote.RoundRobinAddressFunction
All Implemented Interfaces:
Supplier<SocketAddress>

public class RoundRobinAddressFunction extends Object implements Supplier<SocketAddress>
A round-robin connection address supplier that cycles through a list of socket addresses. This implementation uses an atomic counter to ensure thread-safe round-robin selection across multiple addresses.
  • Constructor Details

    • RoundRobinAddressFunction

      public RoundRobinAddressFunction(SocketAddress... addresses)
      Constructs a round-robin address function with the specified socket addresses.
      Parameters:
      addresses - the socket addresses to cycle through; must be non-empty and contain no null elements
      Throws:
      IllegalArgumentException - if addresses is empty or contains null elements
    • RoundRobinAddressFunction

      public RoundRobinAddressFunction(Collection<String> hosts, int port)
      Constructs a round-robin address function from a collection of host names and a port. Creates InetSocketAddress instances for each host with the specified port.
      Parameters:
      hosts - the collection of host names
      port - the port number to use for all addresses
  • Method Details

    • get

      public SocketAddress get()
      Returns the next socket address in round-robin order. This method is thread-safe and will cycle through all addresses indefinitely.
      Specified by:
      get in interface Supplier<SocketAddress>
      Returns:
      the next socket address