Top Description Fields Constructors Methods
com.oracle.bmc.util.internal

public abstract Class RefreshAuthTokenWrapper<REQUEST extends BmcRequest<?>, RESPONSE>

extends Object
implements AsyncHandler<REQUEST extends BmcRequest<?>, RESPONSE>, Future<RESPONSE>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Future, com.oracle.bmc.responses.AsyncHandler
Type Parameters
<REQUEST>
The request type.
<RESPONSE>
The response type.
Imports
com.oracle.bmc.auth.RefreshableOnNotAuthenticatedProvider, .RefreshableOnNotAuthenticatedProvider, com.oracle.bmc.model.BmcException, .BmcException, com.oracle.bmc.requests.BmcRequest, .BmcRequest, com.oracle.bmc.responses.AsyncHandler, .AsyncHandler, jakarta.annotation.Nonnull, org.slf4j.Logger, java.util.concurrent.ExecutionException, .Future, .TimeUnit, .TimeoutException, java.util.function.Function

Combined future and callbacks for asynchronous requests intended to work with some authenticated calls, like instance principals.

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.

Field Summary

Modifier and TypeField and Description
private final RefreshableOnNotAuthenticatedProvider<?>
private volatile int
private Future<RESPONSE>
private final Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>>
private final AsyncHandler<REQUEST, RESPONSE>
private static final Logger
private static final int

Constructor Summary

AccessConstructor and Description
public
RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST, RESPONSE> innerHandler, Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier)

Method Summary

Modifier and TypeMethod and Description
protected abstract void
beforeRetryAction()

Abstract action to be taken before a retry.

protected Future<RESPONSE>

Returns:

response future
buildResponseFuture
()

Call the future supplier to get the response 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 complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public RESPONSE
get()

Implements java.util.concurrent.Future.get.

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.util.concurrent.Future.get.

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.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.

public void
onError(REQUEST
The request that was made.
request
,
Throwable
The error that was received.
error
)

Implements com.oracle.bmc.responses.AsyncHandler.onError.

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.oracle.bmc.responses.AsyncHandler.onSuccess.

Called if the request was successfully completed.

public synchronized boolean

Returns:

false if the retry was not allowed because of the number of attempts
retryCall
()

If we need to retry the request (i.e. on a 401), this method contains the information on how to do that.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authDetailsProviderback to summary
private final RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider
currentAttemptback to summary
private volatile int currentAttempt
delegateback to summary
private Future<RESPONSE> delegate
Annotations
@Nonnull
futureSupplierback to summary
private final Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier
innerHandlerback to summary
private final AsyncHandler<REQUEST, RESPONSE> innerHandler
LOGback to summary
private static final Logger LOG
NUM_TRIES_ALLOWEDback to summary
private static final int NUM_TRIES_ALLOWED

Constructor Detail

RefreshAuthTokenWrapperback to summary
public RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST, RESPONSE> innerHandler, Function<AsyncHandler<REQUEST, RESPONSE>, Future<RESPONSE>> futureSupplier)

Method Detail

beforeRetryActionback to summary
protected abstract void beforeRetryAction()

Abstract action to be taken before a retry.

buildResponseFutureback to summary
protected Future<RESPONSE> buildResponseFuture()

Call the future supplier to get the response future.

Returns:Future<RESPONSE>

response future

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

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 cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning: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 complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
getback to summary
public RESPONSE get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:RESPONSE

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
getback to summary
public RESPONSE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:RESPONSE

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
TimeoutException:
if the wait timed out
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override
onErrorback to summary
public void onError(REQUEST request, Throwable error)

Implements com.oracle.bmc.responses.AsyncHandler.onError.

Doc from com.oracle.bmc.responses.AsyncHandler.onError.

Called if the request could not be completed successfully.

Parameters
request:REQUEST

The request that was made.

error:Throwable

The error that was received.

Annotations
@Override
onSuccessback to summary
public void onSuccess(REQUEST request, RESPONSE response)

Implements com.oracle.bmc.responses.AsyncHandler.onSuccess.

Doc from com.oracle.bmc.responses.AsyncHandler.onSuccess.

Called if the request was successfully completed.

Parameters
request:REQUEST

The request that was made.

response:RESPONSE

The response that was received.

Annotations
@Override
retryCallback 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.

Returns:boolean

false if the retry was not allowed because of the number of attempts