@@ -185,7 +185,7 @@ public static final class Builder {
185
185
/**
186
186
* Connection details.
187
187
*/
188
- private final List <RedisServer > clusterServers = new ArrayList <>();
188
+ private final List <RedisServer > clusterNodes = new ArrayList <>();
189
189
private RedisServer redisServer = null ;
190
190
191
191
/**
@@ -217,52 +217,94 @@ public static final class Builder {
217
217
private Builder () {
218
218
}
219
219
220
- public Builder withServer (final RedisServer redisServer ) {
221
- if (!clusterServers .isEmpty ()) {
222
- // Cannot define both cluster servers and redis server instances.
223
- throw new IllegalArgumentException ("TODO" );
224
- }
225
- this .redisServer = Objects .requireNonNull (redisServer );
226
- return this ;
227
- }
228
-
229
- public Builder withServer (final String host , final int port , final String password ) {
230
- return withServer (new RedisServer (host , port , password ));
231
- }
232
-
220
+ /**
221
+ * Define connection details for connecting to a single Redis server.
222
+ *
223
+ * NOTE: If you want to connect to a RedisCluster, {@link Builder#withClusterNode}.
224
+ *
225
+ * @param host Host of redis server to connect to.
226
+ * @param port Port of redis server to connect to.
227
+ * @return Builder.
228
+ */
233
229
public Builder withServer (final String host , final int port ) {
234
230
return withServer (host , port , null );
235
231
}
236
232
237
-
238
- public Builder withClusters (final RedisServer ...clusterServers ) {
239
- Arrays .stream (clusterServers )
240
- .forEach (this ::withCluster );
241
- return this ;
233
+ /**
234
+ * Define connection details for connecting to a single Redis server.
235
+ *
236
+ * NOTE: If you want to connect to a RedisCluster, {@link Builder#withClusterNode}.
237
+ *
238
+ * @param host Host of redis server to connect to.
239
+ * @param port Port of redis server to connect to.
240
+ * @param password (optional) Password for redis server, or NULL if no password required.
241
+ * @return Builder.
242
+ */
243
+ public Builder withServer (final String host , final int port , final String password ) {
244
+ return withServer (new RedisServer (host , port , password ));
242
245
}
243
246
244
- public Builder withCluster (final RedisServer clusterServer ) {
245
- if (redisServer != null ) {
247
+ /**
248
+ * Define connection details for connecting to a single Redis server.
249
+ *
250
+ * NOTE: If you want to connect to a RedisCluster, {@link Builder#withClusterNode}.
251
+ *
252
+ * @param redisServer Defines a redis server to connect to.
253
+ * @return Builder.
254
+ */
255
+ private Builder withServer (final RedisServer redisServer ) {
256
+ if (!clusterNodes .isEmpty ()) {
246
257
// Cannot define both cluster servers and redis server instances.
247
258
throw new IllegalArgumentException ("TODO" );
248
259
}
249
- clusterServers . add ( Objects .requireNonNull (clusterServer ) );
260
+ this . redisServer = Objects .requireNonNull (redisServer );
250
261
return this ;
251
262
}
252
263
253
- public Builder withCluster (final String host , final int port , final String password ) {
254
- return withCluster (new RedisServer (host , port , password ));
264
+ /**
265
+ * Define connection details for connecting to a RedisCluster.
266
+ * Call this method as many times as needed to add nodes in your cluster.
267
+ *
268
+ * NOTE: If you want to connect to a single redis instance, {@link Builder#withServer}.
269
+ *
270
+ * @param host Host of redis node.
271
+ * @param port Port of redis node.
272
+ * @return Builder.
273
+ */
274
+ public Builder withClusterNode (final String host , final int port ) {
275
+ return withClusterNode (host , port , null );
255
276
}
256
277
257
- public Builder withCluster (final String host , final int port ) {
258
- return withCluster (host , port , null );
278
+ /**
279
+ * Define connection details for connecting to a RedisCluster.
280
+ * Call this method as many times as needed to add nodes in your cluster.
281
+ *
282
+ * NOTE: If you want to connect to a single redis instance, {@link Builder#withServer}.
283
+ *
284
+ * @param host Host of redis node.
285
+ * @param port Port of redis node.
286
+ * @param password (optional) Password for redis node, or NULL if no password required.
287
+ * @return Builder.
288
+ */
289
+ public Builder withClusterNode (final String host , final int port , final String password ) {
290
+ return withClusterNode (new RedisServer (host , port , password ));
259
291
}
260
292
261
- public Builder withCluster (final RedisCluster redisCluster ) {
262
- Objects .requireNonNull (redisCluster );
263
-
264
- this .clusterServers .clear ();
265
- this .clusterServers .addAll (redisCluster .getServers ());
293
+ /**
294
+ * Define connection details for connecting to a RedisCluster.
295
+ * Call this method as many times as needed to add nodes in your cluster.
296
+ *
297
+ * NOTE: If you want to connect to a single redis instance, {@link Builder#withServer}.
298
+ *
299
+ * @param node Defines a node in the RedisCluster.
300
+ * @return Builder.
301
+ */
302
+ private Builder withClusterNode (final RedisServer node ) {
303
+ if (redisServer != null ) {
304
+ // Cannot define both cluster servers and redis server instances.
305
+ throw new IllegalArgumentException ("TODO" );
306
+ }
307
+ clusterNodes .add (Objects .requireNonNull (node ));
266
308
return this ;
267
309
}
268
310
@@ -335,8 +377,8 @@ public Builder withMetricsEnabled(final boolean enabled) {
335
377
*/
336
378
public RedisStreamSpoutConfig build () {
337
379
RedisCluster redisCluster = null ;
338
- if (!clusterServers .isEmpty ()) {
339
- redisCluster = new RedisCluster (clusterServers );
380
+ if (!clusterNodes .isEmpty ()) {
381
+ redisCluster = new RedisCluster (clusterNodes );
340
382
}
341
383
342
384
return new RedisStreamSpoutConfig (
@@ -354,13 +396,16 @@ public RedisStreamSpoutConfig build() {
354
396
}
355
397
}
356
398
399
+ /**
400
+ * Defines a RedisCluster connection details.
401
+ */
357
402
public static class RedisCluster {
358
403
private final List <RedisServer > servers ;
359
404
360
- public RedisCluster ( final RedisServer ... servers ) {
361
- this ( Arrays . asList ( servers ));
362
- }
363
-
405
+ /**
406
+ * Constructor.
407
+ * @param servers One or more Nodes in the RedisCluster.
408
+ */
364
409
public RedisCluster (final List <RedisServer > servers ) {
365
410
Objects .requireNonNull (servers );
366
411
this .servers = Collections .unmodifiableList (new ArrayList <>(servers ));
@@ -377,22 +422,40 @@ public String toString() {
377
422
+ '}' ;
378
423
}
379
424
425
+ /**
426
+ * The URI for connecting to this RedisCluster.
427
+ * @return URI for the cluster.
428
+ */
380
429
public String getConnectString () {
381
430
return getServers ().stream ()
382
431
.map (RedisServer ::getConnectString )
383
432
.collect (Collectors .joining ("," ));
384
433
}
385
434
}
386
435
436
+ /**
437
+ * Defines a Single RedisServer instance connection details.
438
+ */
387
439
public static class RedisServer {
388
440
private final String host ;
389
441
private final int port ;
390
442
private final String password ;
391
443
444
+ /**
445
+ * Constructor.
446
+ * @param host hostname of redis server.
447
+ * @param port port of redis server.
448
+ */
392
449
public RedisServer (final String host , final int port ) {
393
450
this (host , port , null );
394
451
}
395
452
453
+ /**
454
+ * Constructor.
455
+ * @param host hostname of redis server.
456
+ * @param port port of redis server.
457
+ * @param password (optional) password for server, or NULL if not required.
458
+ */
396
459
public RedisServer (final String host , final int port , final String password ) {
397
460
this .host = host ;
398
461
this .port = port ;
@@ -411,10 +474,10 @@ public String getPassword() {
411
474
return password ;
412
475
}
413
476
414
- public boolean hasPassword () {
415
- return password != null ;
416
- }
417
-
477
+ /**
478
+ * The URI for connecting to this Redis Server instance.
479
+ * @return URI for the server.
480
+ */
418
481
public String getConnectString () {
419
482
String connectStr = "redis://" ;
420
483
0 commit comments