* dont use timer if null

* dont use timer if null

* UserPromptTokenProvider public

* synchronized PublicAppTokenProviderBase

* synchronized PublicAppTokenProviderBase

* format

* add comment

* add comment

---------

Co-authored-by: Ohad Bitton <ohbitton@microsoft.com>
This commit is contained in:
ohad bitton 2023-07-26 17:35:30 +03:00 коммит произвёл GitHub
Родитель e2b288d13a
Коммит 5a89292d5e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 21 добавлений и 5 удалений

Просмотреть файл

@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Automatic retries for queued ingestion
* `executeQuery`, `executeMgmt` to call with a specific type.
### Fixed
* Timer was used if authentication throws after client was closed
* Public client credentials (user prompt,device auth) are synchronized - so that users are prompt once
## [5.0.0]
### Fixed

Просмотреть файл

@ -28,6 +28,13 @@ public abstract class PublicAppTokenProviderBase extends MsalTokenProviderBase {
super(clusterUrl, authorityId, httpClient);
}
// This is synchronized as we don't want users to be prompt many times on async operations.
// This way the first thread gets here, finishes and token can be retrieved silently by other threads.
@Override
protected synchronized String acquireAccessTokenImpl() throws DataServiceException, DataClientException {
return super.acquireAccessTokenImpl();
}
@Override
protected void initializeWithCloudInfo(CloudInfo cloudInfo) throws DataClientException, DataServiceException {
super.initializeWithCloudInfo(cloudInfo);

Просмотреть файл

@ -54,7 +54,7 @@ public class ResourceManager implements Closeable, IngestionResourceManager {
public static int UPLOAD_TIMEOUT_MINUTES = 10;
private final Client client;
private final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final Timer timer;
private Timer timer;
private final ReadWriteLock ingestionResourcesLock = new ReentrantReadWriteLock();
private final ReadWriteLock authTokenLock = new ReentrantReadWriteLock();
private final Long defaultRefreshTime;
@ -90,8 +90,10 @@ public class ResourceManager implements Closeable, IngestionResourceManager {
@Override
public void close() {
timer.cancel();
timer.purge();
Timer closeTimer = timer;
timer = null;
closeTimer.cancel();
closeTimer.purge();
}
private RetryConfig buildRetryConfig() {
@ -115,7 +117,9 @@ public class ResourceManager implements Closeable, IngestionResourceManager {
timer.schedule(new RefreshIngestionResourcesTask(), defaultRefreshTime);
} catch (Exception e) {
log.error("Error in refreshIngestionResources. " + e.getMessage(), e);
timer.schedule(new RefreshIngestionResourcesTask(), refreshTimeOnFailure);
if (timer != null) {
timer.schedule(new RefreshIngestionResourcesTask(), refreshTimeOnFailure);
}
}
}
}
@ -128,7 +132,9 @@ public class ResourceManager implements Closeable, IngestionResourceManager {
timer.schedule(new RefreshIngestionAuthTokenTask(), defaultRefreshTime);
} catch (Exception e) {
log.error("Error in refreshIngestionAuthToken. " + e.getMessage(), e);
timer.schedule(new RefreshIngestionAuthTokenTask(), refreshTimeOnFailure);
if (timer != null) {
timer.schedule(new RefreshIngestionAuthTokenTask(), refreshTimeOnFailure);
}
}
}
}