# Class MultipleAddresses

java.lang.Object
org.apache.zookeeper.server.quorum.MultipleAddresses

public final class MultipleAddresses extends Object
This class allows to store several quorum and electing addresses. See ZOOKEEPER-3188 for a discussion of this feature.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Duration`
`DEFAULT_TIMEOUT`

## Constructor Summary

Constructors
Constructor
Description
`MultipleAddresses()`
`MultipleAddresses(InetSocketAddress address)`
`MultipleAddresses(Collection<InetSocketAddress> addresses)`
`MultipleAddresses(Collection<InetSocketAddress> addresses, Duration timeout)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addAddress(InetSocketAddress address)`
`boolean`
`equals(Object o)`
`Set<InetSocketAddress>`
`getAllAddresses()`
Returns all addresses in an unmodifiable set.
`List<String>`
`getAllHostStrings()`
Returns distinct list of all host strings
`List<Integer>`
`getAllPorts()`
Returns all ports
`Set<InetSocketAddress>`
`getAllReachableAddresses()`
Returns a set of all reachable addresses.
`Set<InetSocketAddress>`
`getAllReachableAddressesOrAll()`
Returns a set of all reachable addresses.
`InetSocketAddress`
`getOne()`
Returns an address from the set.
`InetSocketAddress`
`getReachableAddress()`
Returns a reachable address.
`InetSocketAddress`
`getReachableOrOne()`
Returns a reachable address or an arbitrary one, if none is reachable.
`Set<InetSocketAddress>`
`getWildcardAddresses()`
Returns wildcard addresses for all ports
`int`
`hashCode()`
`boolean`
`isEmpty()`
`void`
`recreateSocketAddresses()`
Performs a parallel DNS lookup for all addresses.
`int`
`size()`
Returns the number of addresses in the set.
`String`
`toString()`

### Methods inherited from class Object

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

## Field Details

### DEFAULT_TIMEOUT

public static final Duration DEFAULT_TIMEOUT

## Constructor Details

### MultipleAddresses

public MultipleAddresses()

### MultipleAddresses

public MultipleAddresses(Collection<InetSocketAddress> addresses)

### MultipleAddresses

public MultipleAddresses(InetSocketAddress address)

### MultipleAddresses

public MultipleAddresses(Collection<InetSocketAddress> addresses, Duration timeout)

## Method Details

### isEmpty

public boolean isEmpty()

### getAllAddresses

public Set<InetSocketAddress> getAllAddresses()
Returns all addresses in an unmodifiable set.

Returns:
  set of all InetSocketAddress

### getWildcardAddresses

public Set<InetSocketAddress> getWildcardAddresses()
Returns wildcard addresses for all ports

Returns:
  set of InetSocketAddress with wildcards for all ports

### getAllPorts

public List<Integer> getAllPorts()
Returns all ports

Returns:
  list of all ports

### getAllHostStrings

public List<String> getAllHostStrings()
Returns distinct list of all host strings

Returns:
  list of all hosts

### addAddress

public void addAddress(InetSocketAddress address)

### getReachableAddress

public InetSocketAddress getReachableAddress() throws NoRouteToHostException
Returns a reachable address. If none is reachable than throws exception. The function is nondeterministic in the sense that the result of calling this function twice with the same set of reachable addresses might lead to different results.

Returns:
  address which is reachable.
Throws:
  `NoRouteToHostException` - if none of the addresses are reachable

### getAllReachableAddresses

public Set<InetSocketAddress> getAllReachableAddresses()
Returns a set of all reachable addresses. If none is reachable than returns empty set.

Returns:
  all addresses which are reachable.

### getAllReachableAddressesOrAll

public Set<InetSocketAddress> getAllReachableAddressesOrAll()
Returns a set of all reachable addresses. If none is reachable than returns all addresses.

Returns:
  all reachable addresses, or all addresses if none is reachable.

### getReachableOrOne

public InetSocketAddress getReachableOrOne()
Returns a reachable address or an arbitrary one, if none is reachable. It throws an exception if there are no addresses registered. The function is nondeterministic in the sense that the result of calling this function twice with the same set of reachable addresses might lead to different results.

Returns:
  address which is reachable or fist one.
Throws:
  `NoSuchElementException` - if there is no address registered

### recreateSocketAddresses

public void recreateSocketAddresses()
Performs a parallel DNS lookup for all addresses. If the DNS lookup fails, then address remain unmodified.

### getOne

public InetSocketAddress getOne()
Returns an address from the set.

Returns:
  address from a set.
Throws:
  `NoSuchElementException` - if there is no address registered

### size

public int size()
Returns the number of addresses in the set.

Returns:
  the number of addresses.

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`