39
39
* by each entity/connection is performed. This callback typically propagates
40
40
* the new credentials in the entity state, e.g. sending the new password to the
41
41
* broker for AMQP connections.
42
+ * <p>
43
+ * Instances are preferably created with {@link DefaultCredentialsRefreshServiceBuilder}.
42
44
*/
43
45
public class DefaultCredentialsRefreshService implements CredentialsRefreshService {
44
46
@@ -89,6 +91,13 @@ public class DefaultCredentialsRefreshService implements CredentialsRefreshServi
89
91
*/
90
92
private final Function <Duration , Boolean > approachingExpirationStrategy ;
91
93
94
+ /**
95
+ * Constructor. Consider using {@link DefaultCredentialsRefreshServiceBuilder} to create instances.
96
+ *
97
+ * @param scheduler
98
+ * @param refreshDelayStrategy
99
+ * @param approachingExpirationStrategy
100
+ */
92
101
public DefaultCredentialsRefreshService (ScheduledExecutorService scheduler , Function <Duration , Duration > refreshDelayStrategy , Function <Duration , Boolean > approachingExpirationStrategy ) {
93
102
if (refreshDelayStrategy == null ) {
94
103
throw new IllegalArgumentException ("Refresh delay strategy can not be null" );
@@ -371,6 +380,9 @@ void unregister(String registrationId) {
371
380
}
372
381
}
373
382
383
+ /**
384
+ * Builder to create instances of {@link DefaultCredentialsRefreshServiceBuilder}.
385
+ */
374
386
public static class DefaultCredentialsRefreshServiceBuilder {
375
387
376
388
@@ -385,16 +397,43 @@ public DefaultCredentialsRefreshServiceBuilder scheduler(ScheduledThreadPoolExec
385
397
return this ;
386
398
}
387
399
400
+ /**
401
+ * Set the strategy to schedule credentials refresh after credentials retrieval.
402
+ * <p>
403
+ * Default is a 80 % ratio-based strategy (refresh is scheduled after 80 % of the time
404
+ * before expiration, e.g. 48 minutes for a token with a validity of 60 minutes, that
405
+ * is refresh will be scheduled 12 minutes before the token actually expires).
406
+ *
407
+ * @param refreshDelayStrategy
408
+ * @return this builder instance
409
+ * @see DefaultCredentialsRefreshService#refreshDelayStrategy
410
+ * @see DefaultCredentialsRefreshService#ratioRefreshDelayStrategy(double)
411
+ */
388
412
public DefaultCredentialsRefreshServiceBuilder refreshDelayStrategy (Function <Duration , Duration > refreshDelayStrategy ) {
389
413
this .refreshDelayStrategy = refreshDelayStrategy ;
390
414
return this ;
391
415
}
392
416
417
+ /**
418
+ * Set the strategy to trigger an early refresh before attempting to connect.
419
+ * <p>
420
+ * Default is to never advise to refresh before connecting.
421
+ *
422
+ * @param approachingExpirationStrategy
423
+ * @return this builder instances
424
+ * @see DefaultCredentialsRefreshService#approachingExpirationStrategy
425
+ * @see CredentialsRefreshService#isApproachingExpiration(Duration)
426
+ */
393
427
public DefaultCredentialsRefreshServiceBuilder approachingExpirationStrategy (Function <Duration , Boolean > approachingExpirationStrategy ) {
394
428
this .approachingExpirationStrategy = approachingExpirationStrategy ;
395
429
return this ;
396
430
}
397
431
432
+ /**
433
+ * Create the {@link DefaultCredentialsRefreshService} instance.
434
+ *
435
+ * @return
436
+ */
398
437
public DefaultCredentialsRefreshService build () {
399
438
return new DefaultCredentialsRefreshService (scheduler , refreshDelayStrategy , approachingExpirationStrategy );
400
439
}
0 commit comments