Elffuss BraidHub

kikocis/java-driver public

Merge pull request #340 from olvesh/seeds_to_many_ips

New addContactPoints method for resolving multiple InetAddress from one hostname
Changesetfd4d807e5ca80afda5aaf26d27b98f2219240343641d7d4070086cc9c7e017d5
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-06-17 16:56 +02:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-06-17 16:56 +02:00
Parentsc98c3588aecb, 381c71d88e9a

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +32 −0
@@ -770,6 +770,38 @@
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>