* continue to use the old token.
*/
@Override
protected String getToken() {
verifyProdOnly();
GetAccessTokenResult token = accessToken.get();
if (token == null || isExpired(token)
|| (isAboutToExpire(token) && refreshInProgress.compareAndSet(false, true))) {
lock.lock();
try {
token = accessToken.get();
if (token == null || isAboutToExpire(token)) {
token = appIdentityService.getAccessToken(oauthScopes);
accessToken.set(token);
cacheExpirationHeadroom.set(getNextCacheExpirationHeadroom());
}
} finally {
refreshInProgress.set(false);
lock.unlock();
}
}
return token.getAccessToken();
}