public static class CachedTokenSource.Builder extends Object
CachedTokenSource.
This builder allows configuration of various aspects of token caching behavior, including asynchronous refresh, timing parameters, and initial token state.
| Constructor and Description |
|---|
Builder(TokenSource tokenSource)
Creates a new builder with the specified token source.
|
| Modifier and Type | Method and Description |
|---|---|
CachedTokenSource |
build()
Builds and returns a new
CachedTokenSource instance with the configured parameters. |
CachedTokenSource.Builder |
setAsyncDisabled(boolean asyncDisabled)
Enables or disables asynchronous token refresh.
|
CachedTokenSource.Builder |
setClockSupplier(ClockSupplier clockSupplier)
Sets the clock supplier to use for time-based operations.
|
CachedTokenSource.Builder |
setExpiryBuffer(Duration expiryBuffer)
Sets the buffer duration before token expiry at which the token is considered expired.
|
CachedTokenSource.Builder |
setStaleDuration(Duration staleDuration)
Sets the duration before token expiry at which the token is considered stale.
|
CachedTokenSource.Builder |
setToken(Token token)
Sets an initial token to use in the cache.
|
public Builder(TokenSource tokenSource)
tokenSource - The underlying token source to use for refreshing tokens.NullPointerException - If the token source is null.public CachedTokenSource.Builder setToken(Token token)
If provided, this token will be used immediately without requiring an initial refresh from the underlying token source.
token - The initial token to cache.public CachedTokenSource.Builder setAsyncDisabled(boolean asyncDisabled)
When enabled, stale tokens will trigger a background refresh while continuing to serve the current token. When disabled, all refreshes are performed synchronously and will block the calling thread.
asyncDisabled - True to disable asynchronous refresh, false to enable.public CachedTokenSource.Builder setStaleDuration(Duration staleDuration)
When asynchronous refresh is enabled, tokens that are stale but not yet expired will trigger a background refresh while continuing to serve the current token.
staleDuration - The duration before expiry to consider a token stale. Must be greater
than the expiry buffer duration.public CachedTokenSource.Builder setExpiryBuffer(Duration expiryBuffer)
Tokens within this buffer of their expiry time will be considered expired and require synchronous refresh.
expiryBuffer - The buffer duration before expiry to consider a token expired. Must be
less than the stale duration.public CachedTokenSource.Builder setClockSupplier(ClockSupplier clockSupplier)
This is primarily useful for testing scenarios where you need to control the current time. In production, the default UTC clock supplier should be used.
clockSupplier - The clock supplier to use for determining current time.public CachedTokenSource build()
CachedTokenSource instance with the configured parameters.Copyright © 2026. All rights reserved.