protected synchronized void retrieveToken ( ) { log . debug ( "OAuthTokenManager.retrieveToken" ) ; if ( token == null || ( Long . valueOf ( token . getExpiration ( ) ) < System . currentTimeMillis ( ) / 1000L ) ) { log . debug ( "Token is null, retrieving initial token from provider" ) ; boolean tokenRequest = true ; int retryCount = 0 ; while ( tokenRequest && retryCount < this . iamMaxRetry ) { try { ++ retryCount ; token = provider . retrieveToken ( ) ; tokenRequest = false ; } catch ( OAuthServiceException exception ) { log . debug ( "Exception retrieving IAM token. Returned status code " + exception . getStatusCode ( ) + "Retry attempt " + retryCount ) ; tokenRequest = shouldRetry ( exception . getStatusCode ( ) ) ? true : false ; if ( ! tokenRequest || retryCount == this . iamMaxRetry ) throw exception ; } } if ( null == token ) throw new OAuthServiceException ( "Null token returned by the Token Provider" ) ; cacheToken ( token ) ; } }
retrieve token from provider . Ensures each thread checks the token is null prior to making the callout to IAM