org.apache.ignite.configuration

## Class BasicAddressResolver

- java.lang.Object
- - org.apache.ignite.configuration.BasicAddressResolver

All Implemented Interfaces:
  AddressResolver

    public class BasicAddressResolver
    extends Object
    implements AddressResolver

Basic implementation of `AddressResolver`.

Allows to provide simple mapping between different address, which is useful different parts of the cluster are located in different subnetworks and port forwarding on the router is used for communication between them. Another common case is Docker environment which can create a pair of public and private address per container.

There are two different types of mapping supported by this implementation of `AddressResolver`.

First type maps specific socket addresses (host and port pairs) are mapped to each other. This is useful for port forwarding, where multiple nodes will typically map to the same external address (router), but with different port numbers. Here is the example:

     <property name="addressResolver">
         <bean class="org.apache.ignite.configuration.BasicAddressResolver">
             <constructor-arg>
                 <map>
                     <entry key="10.0.0.1:47100" value="123.123.123.123:1111"/>
                     <entry key="10.0.0.2:47100" value="123.123.123.123:2222"/>
                     <entry key="10.0.0.3:47100" value="123.123.123.123:3333"/>
                 </map>
             </constructor-arg>
         </bean>
     </property>

Second type maps one host to another. In this case any internal address a node is bound to will be mapped to the corresponding external host with the same host number. Here is the example:

     <property name="addressResolver">
         <bean class="org.apache.ignite.configuration.BasicAddressResolver">
             <constructor-arg>
                 <map>
                     <entry key="10.0.0.1" value="123.123.123.123"/>
                 </map>
             </constructor-arg>
         </bean>
     </property>

Here any port on `10.0.0.1` will be mapped to the same port number on `123.123.123.123`. E.g., `10.0.0.1:47100` will be mapped to `123.123.123.123:47100`, and `10.0.0.1:47500` will be mapped to `123.123.123.123:47500`.

Two types of mappings described above can be mixed within one address resolver.

### Constructor Summary

Constructors
Constructor and Description
`BasicAddressResolver(Map<String,String> addrMap)` Created the address resolver.

### Method Summary

All Methods Instance Methods Concrete Methods
`Collection<InetSocketAddress>` `getExternalAddresses(InetSocketAddress addr)` Maps internal address to a collection of external addresses.
`String` `toString()`

### Methods inherited from class java.lang.Object

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

### Constructor Detail

#### BasicAddressResolver

    public BasicAddressResolver(Map<String,String> addrMap)
                         throws UnknownHostException

Created the address resolver.

Parameters:
  `addrMap` - Address mappings.
Throws:
  `UnknownHostException` - If any of the hosts can't be resolved.

### Method Detail

#### getExternalAddresses

    public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr)
                                                       throws IgniteCheckedException

Maps internal address to a collection of external addresses.

Specified by:
  `getExternalAddresses` in interface `AddressResolver`
Parameters:
  `addr` - Internal (local) address.
Returns:
  Collection of addresses that this local address is "known" outside. Note that if there are more than one external network the local address can be mapped differently to each and therefore may need to return multiple external addresses.
Throws:
  `IgniteCheckedException` - Thrown if any exception occurs.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.16.0
Release Date | : December 15 2023