public class BackOffTaskScheduler extends Object
It is used by JWTSignatureValidator to perform immediate (out of regular schedule) keys refresh upon detection of unknown keys. The objective is to detect rotation of JWT signing keys on authorization server very quickly in order to minimize the mismatch between valid / invalid keys on the Kafka broker and on the authorization server. Until the keys are in-sync with the authorization server, the mismatch causes 'invalid token' errors for valid new tokens, and keeps the Kafka broker accepting the no-longer-valid tokens.
This scheduler works in tandem with periodic keys refresh job in JWTSignatureValidator, using the same ScheduledExecutorService, running the tasks on the same thread. While the periodic refresh is triggered on a regular schedule, and is unaware of any other tasks, this class runs the refresh task on demand as a one-off, but tries hard to succeed - it reschedules the task if it fails.
If the task has already been scheduled (by calling scheduleTask()
and has not yet successfully completed,
another request to schedule the task will be ignored.
If the scheduled task fails during its run, it will be rescheduled using the so called 'exponentional backoff' delay.
Rather than being attempted again immediately, it will pause for an ever increasing time delay until some cutoff delay
is reached (cutoffIntervalSeconds
) when no further attempts are schedule, and another scheduleTask()
call can again trigger a new refresh.
Constructor and Description |
---|
BackOffTaskScheduler(ScheduledExecutorService executor,
int minPauseSeconds,
int cutoffIntervalSeconds,
Runnable task)
Initialise a new scheduler instance
|
Modifier and Type | Method and Description |
---|---|
int |
getCutoffIntervalSeconds() |
int |
getMinPauseSeconds() |
boolean |
scheduleTask()
Schedule a task.
|
public BackOffTaskScheduler(ScheduledExecutorService executor, int minPauseSeconds, int cutoffIntervalSeconds, Runnable task)
executor
- Single threaded executor service, also used by periodic keys refresh jobminPauseSeconds
- A minimum pause before starting the task, and between any subsequent attemptcutoffIntervalSeconds
- If exponential backoff pause exceeds this interval, the task is cancelledtask
- The task that refreshes the keyspublic int getMinPauseSeconds()
public int getCutoffIntervalSeconds()
public boolean scheduleTask()
Copyright © 2022. All rights reserved.