private static Result < Jwt > renewCCTokenSync ( final Jwt jwt ) { // Already expired, try to renew getCCTokenSynchronously but let requests use the old token. logger . trace ( "In renew window and token is already expired." ) ; //the token can be renew when it's not on renewing or current time is lager than retrying interval if ( ! jwt . isRenewing ( ) || System . currentTimeMillis ( ) > jwt . getExpiredRetryTimeout ( ) ) { jwt . setRenewing ( true ) ; jwt . setEarlyRetryTimeout ( System . currentTimeMillis ( ) + Jwt . getExpiredRefreshRetryDelay ( ) ) ; Result < Jwt > result = getCCTokenRemotely ( jwt ) ; //set renewing flag to false no mater fail or success jwt . setRenewing ( false ) ; return result ; } else { if ( logger . isTraceEnabled ( ) ) logger . trace ( "Circuit breaker is tripped and not timeout yet!" ) ; // token is renewing return Failure . of ( new Status ( STATUS_CLIENT_CREDENTIALS_TOKEN_NOT_AVAILABLE ) ) ; } }
renew Client Credential token synchronously . When success will renew the Jwt jwt passed in . When fail will return Status code so that can be handled by caller .