|
19 | 19 | package org.neo4j.driver.v1;
|
20 | 20 |
|
21 | 21 | import java.net.URI;
|
22 |
| -import java.util.List; |
23 | 22 |
|
24 | 23 | import org.neo4j.driver.internal.DriverFactory;
|
25 | 24 | import org.neo4j.driver.internal.cluster.RoutingSettings;
|
26 | 25 | import org.neo4j.driver.internal.retry.RetrySettings;
|
27 | 26 | import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
|
28 | 27 |
|
| 28 | +import static org.neo4j.driver.internal.DriverFactory.BOLT_ROUTING_URI_SCHEME; |
| 29 | + |
29 | 30 | /**
|
30 | 31 | * Creates {@link Driver drivers}, optionally letting you {@link #driver(URI, Config)} to configure them.
|
31 | 32 | * @see Driver
|
@@ -135,42 +136,44 @@ public static Driver driver( URI uri, AuthToken authToken, Config config )
|
135 | 136 | }
|
136 | 137 |
|
137 | 138 | /**
|
138 |
| - * Try to create a bolt+routing driver from the first available address. |
139 |
| - * This is wrapper for the {@link #driver} method that finds the first |
| 139 | + * Try to create a bolt+routing driver from the <b>first</b> available address. |
| 140 | + * This is wrapper for the {@link #driver} method that finds the <b>first</b> |
140 | 141 | * server to respond positively.
|
141 | 142 | *
|
142 |
| - * @param addresses a list of server addresses for Neo4j instances |
| 143 | + * @param routingUris an {@link Iterable} of server {@link URI}s for Neo4j instances. All given URIs should |
| 144 | + * have 'bolt+routing' scheme. |
143 | 145 | * @param authToken authentication to use, see {@link AuthTokens}
|
144 | 146 | * @param config user defined configuration
|
145 | 147 | * @return a new driver instance
|
146 | 148 | */
|
147 |
| - public static Driver routingDriverFromFirstAvailableAddress( List<String> addresses, AuthToken authToken, Config config ) |
| 149 | + public static Driver routingDriver( Iterable<URI> routingUris, AuthToken authToken, Config config ) |
148 | 150 | {
|
149 |
| - for( String address: addresses ) |
| 151 | + assertRoutingUris( routingUris ); |
| 152 | + |
| 153 | + for ( URI uri : routingUris ) |
150 | 154 | {
|
151 | 155 | try
|
152 | 156 | {
|
153 |
| - return driver( "bolt+routing://" + address, authToken, config ); |
| 157 | + return driver( uri, authToken, config ); |
154 | 158 | }
|
155 |
| - catch( ServiceUnavailableException e ) |
| 159 | + catch ( ServiceUnavailableException e ) |
156 | 160 | {
|
157 | 161 | // try the next one
|
158 | 162 | }
|
159 | 163 | }
|
| 164 | + |
160 | 165 | throw new ServiceUnavailableException( "Failed to discover an available server" );
|
161 | 166 | }
|
162 | 167 |
|
163 |
| - /** |
164 |
| - * Try to create a bolt+routing driver from the first available address. |
165 |
| - * This is wrapper for the {@link #driver} method that finds the first |
166 |
| - * server to respond positively. |
167 |
| - * |
168 |
| - * @param addresses a list of server addresses for Neo4j instances |
169 |
| - * @param authToken authentication to use, see {@link AuthTokens} |
170 |
| - * @return a new driver instance |
171 |
| - */ |
172 |
| - public static Driver routingDriverFromFirstAvailableAddress( List<String> addresses, AuthToken authToken ) |
| 168 | + private static void assertRoutingUris( Iterable<URI> uris ) |
173 | 169 | {
|
174 |
| - return routingDriverFromFirstAvailableAddress( addresses, authToken, Config.defaultConfig() ); |
| 170 | + for ( URI uri : uris ) |
| 171 | + { |
| 172 | + if ( !BOLT_ROUTING_URI_SCHEME.equals( uri.getScheme() ) ) |
| 173 | + { |
| 174 | + throw new IllegalArgumentException( |
| 175 | + "Illegal URI scheme, expected '" + BOLT_ROUTING_URI_SCHEME + "' in '" + uri + "'" ); |
| 176 | + } |
| 177 | + } |
175 | 178 | }
|
176 | 179 | }
|
0 commit comments