kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | fd4d807e5ca80afda5aaf26d27b98f2219240343641d7d4070086cc9c7e017d5 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-17 16:56 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-17 16:56 +02:00 |
| Parents | c98c3588aecb, 381c71d88e9a |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +32 −0
| @@ -770,6 +770,38 @@ | ||
| 770 | 770 | return this; |
| 771 | 771 | } |
| 772 | 772 | |
| 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 | + | |
| 773 | 805 | /** |
| 774 | 806 | * Adds contact points. |
| 775 | 807 | * <p> |