io.sphere.sdk.client.OnDemandSphereAccessTokenSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commercetools-java-client-core Show documentation
Show all versions of commercetools-java-client-core Show documentation
This SDK is announced to be deprecated latest by 31 December 2022, please follow more details on SDK deprecation plan https://docs.commercetools.com/api/releases/2021-08-31-announced-long-term-support-plan-for-commercetools-sdks. We recommend you to use our new SDK here https://docs.commercetools.com/sdk/jvm-sdk#java-sdk-v2.
package io.sphere.sdk.client;
import io.sphere.sdk.http.HttpClient;
import java.util.concurrent.CompletionStage;
final class OnDemandSphereAccessTokenSupplier extends AutoCloseableService implements SphereAccessTokenSupplier {
private final TokensSupplier tokensSupplier;
private OnDemandSphereAccessTokenSupplier(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) {
tokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient);
}
@Override
protected synchronized void internalClose() {
if (!isClosed()) {
tokensSupplier.close();
}
}
@Override
public CompletionStage get() {
rejectExcutionIfClosed("Token supplier is already closed.");
return tokensSupplier.get().thenApply(Tokens::getAccessToken);
}
public static OnDemandSphereAccessTokenSupplier of(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) {
return new OnDemandSphereAccessTokenSupplier(config, httpClient, closeHttpClient);
}
}