Interface AddressTranslator
-
- All Known Implementing Classes:
EC2MultiRegionAddressTranslator,IdentityTranslator
public interface AddressTranslatorTranslates IP addresses received from Cassandra nodes into locally queriable addresses.The driver auto-detect new Cassandra nodes added to the cluster through server side pushed notifications and through checking the system tables. For each node, the address the driver will receive will correspond to the address set as
rpc_addressin the node yaml file. In most case, this is the correct address to use by the driver and that is what is used by default. However, sometimes the addresses received through this mechanism will either not be reachable directly by the driver or should not be the preferred address to use to reach the node (for instance, therpc_addressset on Cassandra nodes might be a private IP, but some clients may have to use a public IP, or pass by a router to reach that node). This interface allows to deal with such cases, by allowing to translate an address as sent by a Cassandra node to another address to be used by the driver for connection.Please note that the contact points addresses provided while creating the
Clusterinstance are not "translated", only IP address retrieved from or sent by Cassandra nodes to the driver are.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Called atClustershutdown.voidinit(Cluster cluster)Initializes this address translator.InetSocketAddresstranslate(InetSocketAddress address)Translates a Cassandrarpc_addressto another address if necessary.
-
-
-
Method Detail
-
init
void init(Cluster cluster)
Initializes this address translator.- Parameters:
cluster- theClusterinstance for which the translator is created.
-
translate
InetSocketAddress translate(InetSocketAddress address)
Translates a Cassandrarpc_addressto another address if necessary.- Parameters:
address- the address of a node as returned by Cassandra. Note that if therpc_addressof a node has been configured to0.0.0.0server side, then the provided address will be the nodelisten_address, *not*0.0.0.0. Also note that the port forInetSocketAddresswill always be the one set at Cluster construction time (9042 by default).- Returns:
- the address the driver should actually use to connect to the node designated by
address. If the return isnull, thenaddresswill be used by the driver (it is thus equivalent to returningaddressdirectly)
-
close
void close()
Called atClustershutdown.
-
-