Skip to content

Commit 0bef855

Browse files
committed
Merge pull request apache#340 from olvesh/seeds_to_many_ips
New addContactPoints method for resolving multiple InetAddress from one hostname
2 parents 37db9ed + 13cd27b commit 0bef855

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • driver-core/src/main/java/com/datastax/driver/core

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,38 @@ public Builder addContactPoints(String... addresses) {
770770
return this;
771771
}
772772

773+
/**
774+
* Adds a contact point - or many if it host resolves to multiple <code>InetAddress</code>s (A records).
775+
* <p>
776+
*
777+
* If the host name points to a dns records with multiple a-records, all InetAddresses
778+
* returned will be used. Make sure that all resulting <code>InetAddress</code>s returned
779+
* points to the same cluster and datacenter.
780+
* <p>
781+
* See {@link Builder#addContactPoint} for more details on contact
782+
* points and thrown exceptions
783+
*
784+
* @param address address of the nodes to look up InetAddresses from to add as contact points.
785+
* @return this Builder.
786+
*
787+
*
788+
* @see Builder#addContactPoint
789+
*/
790+
public Builder addContactPoints(String address) {
791+
// We explicitely check for nulls because InetAdress.getByName() will happily
792+
// accept it and use localhost (while a null here almost likely mean a user error,
793+
// not "connect to localhost")
794+
if (address == null)
795+
throw new NullPointerException();
796+
797+
try {
798+
addContactPoints(InetAddress.getAllByName(address));
799+
} catch (UnknownHostException e) {
800+
throw new IllegalArgumentException(e.getMessage());
801+
}
802+
return this;
803+
}
804+
773805
/**
774806
* Adds contact points.
775807
* <p>

0 commit comments

Comments
 (0)