This handler wraps a base AsyncHandler and has additional logic so that if a call fails with a 401, we'll refresh the auth token and then try again up to a given number of retries (it is recommended that we only do one retry).
It also wraps a delegate Future, and when the result of the future is requested, but the call fails with a 401, we perform the additional logic described above.
This is to account for scenarios where we have a valid/non-expired token but the permissions for the instance have changed since the token was issued and so on the server-side the presented token is considered invalid.
| Modifier and Type | Field and Description |
|---|---|
| private final RefreshableOnNotAuthenticatedProvider | |
| private volatile int | |
| private Future | |
| private final Function | |
| private final AsyncHandler | |
| private static final Logger | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public | RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST, RESPONSE> innerHandler, Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier)
|
| Modifier and Type | Method and Description |
|---|---|
| protected abstract void | |
| protected Future | |
| public boolean | cancel(boolean
true if the thread
executing this task should be interrupted (if the thread is
known to the implementation); otherwise, in-progress tasks are
allowed to completeImplements java. Attempts to cancel execution of this task. |
| public RESPONSE | get()
Implements java. Waits if necessary for the computation to complete, and then retrieves its result. |
| public RESPONSE | get(long
the maximum time to wait timeout, TimeUnit the time unit of the timeout argument unit)Implements java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. |
| public boolean | isCancelled()
Implements java. Returns |
| public boolean | |
| public void | onError(REQUEST
The request that was made. request, Throwable The error that was received. error)Implements com. Called if the request could not be completed successfully. |
| public void | onSuccess(REQUEST
The request that was made. request, RESPONSE The response that was received. response)Implements com. Called if the request was successfully completed. |
| public synchronized boolean | Returns: false if the retry was not allowed because of the number of attemptsIf we need to retry the request (i.e. on a 401), this method contains the information on how to do that. |
| authDetailsProvider | back to summary |
|---|---|
| private final RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider | |
| currentAttempt | back to summary |
|---|---|
| private volatile int currentAttempt | |
| delegate | back to summary |
|---|---|
| private Future<RESPONSE> delegate
| |
| futureSupplier | back to summary |
|---|---|
| private final Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier | |
| innerHandler | back to summary |
|---|---|
| private final AsyncHandler<REQUEST, RESPONSE> innerHandler | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| NUM_TRIES_ALLOWED | back to summary |
|---|---|
| private static final int NUM_TRIES_ALLOWED | |
| RefreshAuthTokenWrapper | back to summary |
|---|---|
| public RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST, RESPONSE> innerHandler, Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier) | |
| beforeRetryAction | back to summary |
|---|---|
| protected abstract void beforeRetryAction() Abstract action to be taken before a retry. | |
| buildResponseFuture | back to summary |
|---|---|
| protected Future Call the future supplier to get the response future.
| |
| cancel | back to summary |
|---|---|
| public boolean cancel(boolean mayInterruptIfRunning) Implements java. Doc from java. Attempts to cancel execution of this task. This method has no
effect if the task is already completed or cancelled, or could
not be cancelled for some other reason. Otherwise, if this
task has not started when The return value from this method does not necessarily
indicate whether the task is now cancelled; use
| |
| get | back to summary |
|---|---|
| public RESPONSE get() throws InterruptedException, ExecutionException Implements java. Doc from java. Waits if necessary for the computation to complete, and then retrieves its result.
| |
| get | back to summary |
|---|---|
| public RESPONSE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Implements java. Doc from java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
| |
| isCancelled | back to summary |
|---|---|
| public boolean isCancelled() Implements java. Doc from java. Returns
| |
| isDone | back to summary |
|---|---|
| public boolean isDone() Implements java. Doc from java. Returns
| |
| onError | back to summary |
|---|---|
| public void onError(REQUEST request, Throwable error) Implements com. Doc from com. Called if the request could not be completed successfully. | |
| onSuccess | back to summary |
|---|---|
| public void onSuccess(REQUEST request, RESPONSE response) Implements com. Doc from com. Called if the request was successfully completed.
| |
| retryCall | back to summary |
|---|---|
| public synchronized boolean retryCall() If we need to retry the request (i.e. on a 401), this method contains the information on how to do that. This method will be leveraged by the onError callback of this handler.
| |