All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.client.PlayJavaSphereClientImpl Maven / Gradle / Ivy

package io.sphere.sdk.client;

import play.libs.F;

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) {
        F.RedeemablePromise promise = F.RedeemablePromise.empty();
        stage.whenCompleteAsync((value, throwable) -> {
            if (throwable == null) {
                promise.success(value);
            } else {
                promise.failure(throwable);
            }
        });
        return promise;
    }

    public static PlayJavaSphereClient of(final SphereClient sphereClient) {
        return new PlayJavaSphereClientImpl(sphereClient);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy