@@ -61,8 +61,7 @@ public class Config
61
61
/** Strategy for how to trust encryption certificate */
62
62
private final TrustStrategy trustStrategy ;
63
63
64
- private final int minServersInCluster ;
65
- private final int maxRoutingFailures ;
64
+ private final int routingFailureLimit ;
66
65
private final long routingRetryDelayMillis ;
67
66
68
67
private Config ( ConfigBuilder builder )
@@ -74,8 +73,7 @@ private Config( ConfigBuilder builder)
74
73
75
74
this .encryptionLevel = builder .encryptionLevel ;
76
75
this .trustStrategy = builder .trustStrategy ;
77
- this .minServersInCluster = builder .minServersInCluster ;
78
- this .maxRoutingFailures = builder .maxRoutingFailures ;
76
+ this .routingFailureLimit = builder .routingFailureLimit ;
79
77
this .routingRetryDelayMillis = builder .routingRetryDelayMillis ;
80
78
}
81
79
@@ -152,7 +150,7 @@ public static Config defaultConfig()
152
150
153
151
RoutingSettings routingSettings ()
154
152
{
155
- return new RoutingSettings ( maxRoutingFailures , routingRetryDelayMillis );
153
+ return new RoutingSettings ( routingFailureLimit , routingRetryDelayMillis );
156
154
}
157
155
158
156
/**
@@ -166,8 +164,7 @@ public static class ConfigBuilder
166
164
private EncryptionLevel encryptionLevel = EncryptionLevel .REQUIRED_NON_LOCAL ;
167
165
private TrustStrategy trustStrategy = trustOnFirstUse (
168
166
new File ( getProperty ( "user.home" ), ".neo4j" + File .separator + "known_hosts" ) );
169
- public int minServersInCluster = 3 ;
170
- private int maxRoutingFailures = 10 ;
167
+ private int routingFailureLimit = 1 ;
171
168
private long routingRetryDelayMillis = 5_000 ;
172
169
173
170
private ConfigBuilder () {}
@@ -279,14 +276,25 @@ public ConfigBuilder withTrustStrategy( TrustStrategy trustStrategy )
279
276
* The routing servers are tried in order. If connecting any of them fails, they are all retried after
280
277
* {@linkplain #withRoutingRetryDelay a delay}. This process of retrying all servers is then repeated for the
281
278
* number of times specified here before considering the cluster unavailable.
279
+ * <p>
280
+ * The default value of this parameter is {@code 1}, which means that the the driver will not re-attempt to
281
+ * connect to the cluster when connecting has failed to each individual server in the list of routers. This
282
+ * default value is sensible under this assumption that if the attempt to connect fails for all servers, then
283
+ * the entire cluster is down, or the client is disconnected from the network, and retrying to connect will
284
+ * not bring it back up, in which case it is better to report the failure sooner.
282
285
*
283
- * @param routingRetryLimit
286
+ * @param routingFailureLimit
284
287
* the number of times to retry each server in the list of routing servers
285
288
* @return this builder
286
289
*/
287
- public ConfigBuilder withRoutingRetryLimit ( int routingRetryLimit )
290
+ public ConfigBuilder withRoutingFailureLimit ( int routingFailureLimit )
288
291
{
289
- this .maxRoutingFailures = routingRetryLimit ;
292
+ if ( routingFailureLimit < 1 )
293
+ {
294
+ throw new IllegalArgumentException (
295
+ "The failure limit may not be smaller than 1, but was: " + routingFailureLimit );
296
+ }
297
+ this .routingFailureLimit = routingFailureLimit ;
290
298
return this ;
291
299
}
292
300
@@ -297,13 +305,15 @@ public ConfigBuilder withRoutingRetryLimit( int routingRetryLimit )
297
305
* The delay is measured from when the first attempt to connect was made, so that the delay time specifies a
298
306
* retry interval.
299
307
* <p>
300
- * For each {@linkplain #withRoutingRetryLimit retry attempt} the delay time will be doubled. The time
308
+ * For each {@linkplain #withRoutingFailureLimit retry attempt} the delay time will be doubled. The time
301
309
* specified here is the base time, i.e. the time to wait before the first retry. If that attempt (on all
302
310
* servers) also fails, the delay before the next retry will be double the time specified here, and the next
303
311
* attempt after that will be double that, et.c. So if, for example, the delay specified here is
304
312
* {@code 5 SECONDS}, then after attempting to connect to each server fails reconnecting will be attempted
305
313
* 5 seconds after the first connection attempt to the first server. If that attempt also fails to connect to
306
314
* all servers, the next attempt will start 10 seconds after the second attempt started.
315
+ * <p>
316
+ * The default value of this parameter is {@code 5 SECONDS}.
307
317
*
308
318
* @param delay
309
319
* the amount of time between attempts to reconnect to the same server
@@ -313,7 +323,13 @@ public ConfigBuilder withRoutingRetryLimit( int routingRetryLimit )
313
323
*/
314
324
public ConfigBuilder withRoutingRetryDelay ( long delay , TimeUnit unit )
315
325
{
316
- this .routingRetryDelayMillis = unit .toMillis ( delay );
326
+ long routingRetryDelayMillis = unit .toMillis ( delay );
327
+ if ( routingRetryDelayMillis < 0 )
328
+ {
329
+ throw new IllegalArgumentException ( String .format (
330
+ "The retry delay may not be smaller than 0, but was %d %s." , delay , unit ) );
331
+ }
332
+ this .routingRetryDelayMillis = routingRetryDelayMillis ;
317
333
return this ;
318
334
}
319
335
0 commit comments