@ThreadSafe class RefreshableTask<T> extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
RefreshableTask.Builder<T> |
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicBoolean |
asyncRefreshing
Used to ensure only one thread at any given time refreshes the value.
|
private static long |
BLOCKING_REFRESH_MAX_WAIT_IN_SECONDS
Maximum time to wait for a blocking refresh lock before calling refresh again.
|
private java.util.concurrent.locks.Lock |
blockingRefreshLock
Used to synchronize a blocking refresh.
|
private java.util.concurrent.ExecutorService |
executor
Single threaded executor to asynchronous refresh the value.
|
private java.util.concurrent.atomic.AtomicReference<T> |
refreshableValueHolder
Atomic holder for refreshable value.
|
private java.util.concurrent.Callable<T> |
refreshCallable
Callback to get a new refreshed value.
|
private SdkPredicate<T> |
shouldDoAsyncRefresh
Predicate to determine whether a async refresh can be done rather than a blocking refresh.
|
private SdkPredicate<T> |
shouldDoBlockingRefresh
Predicate to determine whether a blocking refresh should be performed
|
Modifier | Constructor and Description |
---|---|
private |
RefreshableTask(java.util.concurrent.Callable<T> refreshCallable,
SdkPredicate<T> shouldDoBlockingRefresh,
SdkPredicate<T> shouldDoAsyncRefresh) |
Modifier and Type | Method and Description |
---|---|
private void |
asyncRefresh()
Used to asynchronously refresh the value.
|
private void |
blockingRefresh()
Used when there is no valid value to return.
|
T |
forceGetValue()
Forces a refresh of the value.
|
private T |
getRefreshedValue() |
T |
getValue()
Return a valid value, refreshing if necessary.
|
private void |
handleInterruptedException(java.lang.String message,
java.lang.InterruptedException cause)
If we are interrupted while waiting for a lock we just restore the interrupt status and throw
an AmazonClientException back to the caller.
|
private void |
refreshValue()
Invokes the callback to get a new value.
|
private boolean |
shouldDoAsyncRefresh() |
private boolean |
shouldDoBlockingRefresh() |
private static final long BLOCKING_REFRESH_MAX_WAIT_IN_SECONDS
private final java.util.concurrent.locks.Lock blockingRefreshLock
private final java.util.concurrent.atomic.AtomicReference<T> refreshableValueHolder
private final java.util.concurrent.ExecutorService executor
private final java.util.concurrent.atomic.AtomicBoolean asyncRefreshing
private final java.util.concurrent.Callable<T> refreshCallable
private final SdkPredicate<T> shouldDoBlockingRefresh
private final SdkPredicate<T> shouldDoAsyncRefresh
private RefreshableTask(java.util.concurrent.Callable<T> refreshCallable, SdkPredicate<T> shouldDoBlockingRefresh, SdkPredicate<T> shouldDoAsyncRefresh)
public T getValue() throws AmazonClientException, java.lang.IllegalStateException
AmazonClientException
- If error occurs during refresh.java.lang.IllegalStateException
- If value if invalid after refreshing.public T forceGetValue()
AmazonClientException
- If error occurs during refresh.java.lang.IllegalStateException
- If value if invalid after refreshing.private T getRefreshedValue() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- If the refreshed value is still invalid.private boolean shouldDoBlockingRefresh()
private boolean shouldDoAsyncRefresh()
private void blockingRefresh()
private void asyncRefresh()
private void refreshValue()
private void handleInterruptedException(java.lang.String message, java.lang.InterruptedException cause)