Elffuss BraidHub

kikocis/java-driver public

This will make the cluster not only use the first available InetAddress but all that is returned from the host lookup.

This will greatly simplify setups as we can add a single cassandra_seeds dns record and have that statically added to our configuration.
Changeset381c71d88e9aaa6eb07578886bdf7b21070aefe38d0416b6cf4b0533addf0b6b
AuthorOlve Sæther Hansen <olve@vimond.com> · 2015-05-13 12:21 +02:00
CommitterOlve Sæther Hansen <olve@vimond.com> · 2015-05-13 12:21 +02:00
Parents5b2ba50eec1f

Browse the files at this changeset

1 file changed

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