public class RefreshableResponseProvider<T extends RefreshableResponseProvider.ExpiringResponse> extends Object
getUnexpiredResponse() which is
intended to execute quickly).
Strategy is to use a dedicated thread-scheduled executor service, to retrieve and set your
ExpiringResponse to be always up-to-date.
Token provider which handles refreshing tokens on a configurable interval.
Note that this implementation does not incur any synchronization; rather it is assumed the refresh interval is less than the maximum time for token so that while the token is refreshing the current token continues to be valid.
Adapted from HERE DG class RefreshableTokenAuthenticationProvider.
| Modifier and Type | Class and Description |
|---|---|
static interface |
RefreshableResponseProvider.ExpiringResponse
Various tokens and keys might be set up in the system to be expiring.
|
static interface |
RefreshableResponseProvider.ResponseRefresher<T extends RefreshableResponseProvider.ExpiringResponse>
You can call a response refresher to refresh a previous ExpiringResponse,
to keep it unexpired.
|
| Constructor and Description |
|---|
RefreshableResponseProvider(Clock clock,
Long refreshIntervalMillis,
T initialResponse,
RefreshableResponseProvider.ResponseRefresher<T> refreshResponseFunction,
ScheduledExecutorService scheduledExecutorService) |
RefreshableResponseProvider(Long refreshIntervalMillis,
T initialResponse,
RefreshableResponseProvider.ResponseRefresher<T> refreshResponseFunction)
Create a RefreshableResponseProvider with optional refreshIntervalMillis, initialResponse,
and refreshResponseFunction.
|
| Modifier and Type | Method and Description |
|---|---|
static ScheduledExecutorService |
getScheduledExecutorServiceSize1()
Gets a here-auth-refresh ScheduledExecutorService with 1 core pool thread.
|
T |
getUnexpiredResponse()
Gets the current unexpired response.
|
protected void |
scheduleTokenRefresh(long millis)
Schedule the next refresh with the specified timeout duration
|
void |
shutdown()
Shutdown the background threads
|
public RefreshableResponseProvider(Long refreshIntervalMillis, T initialResponse, RefreshableResponseProvider.ResponseRefresher<T> refreshResponseFunction)
refreshIntervalMillis - optional. only specify during tests, not in real code.
if you want to ignore the normal response
expires_in,
and instead refresh on a fixed interval not set by the HERE authorization server,
specify this value in milliseconds.initialResponse - the initial value of an active responserefreshResponseFunction - the ability to refresh and get a new response prior to the
previous one expiring.public RefreshableResponseProvider(Clock clock, Long refreshIntervalMillis, T initialResponse, RefreshableResponseProvider.ResponseRefresher<T> refreshResponseFunction, ScheduledExecutorService scheduledExecutorService)
public static ScheduledExecutorService getScheduledExecutorServiceSize1()
public void shutdown()
public T getUnexpiredResponse()
protected void scheduleTokenRefresh(long millis)
millis - time (msec) in the future to schedule the refreshCopyright © 2023 HERE Europe B.V. All Rights Reserved.