
io.sphere.sdk.client.PlayJavaSphereClientImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commercetools-play-2_2-java-client_2.10 Show documentation
Show all versions of commercetools-play-2_2-java-client_2.10 Show documentation
commercetools-play-2_2-java-client
package io.sphere.sdk.client;
import play.libs.F;
import scala.concurrent.Promise;
import scala.concurrent.Promise$;
import java.util.concurrent.CompletionStage;
final class PlayJavaSphereClientImpl implements PlayJavaSphereClient {
private final SphereClient sphereClient;
private PlayJavaSphereClientImpl(final SphereClient sphereClient) {
this.sphereClient = sphereClient;
}
@Override
public F.Promise execute(final SphereRequest sphereRequest) {
return convert(sphereClient.execute(sphereRequest));
}
@Override
public void close() {
sphereClient.close();
}
private static F.Promise convert(final CompletionStage stage) {
final Promise scalaPromise = Promise$.MODULE$.apply();
stage.whenCompleteAsync((value, throwable) -> {
if (throwable == null) {
scalaPromise.success(value);
} else {
scalaPromise.failure(throwable);
}
});
return F.Promise.wrap(scalaPromise.future());
}
public static PlayJavaSphereClient of(final SphereClient sphereClient) {
return new PlayJavaSphereClientImpl(sphereClient);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy