com.yandex.ydb.core.grpc.UnaryStreamToFuture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-sdk-jdbc-uberjar Show documentation
Show all versions of ydb-sdk-jdbc-uberjar Show documentation
JDBC client implementation over Table client, single jar
package com.yandex.ydb.core.grpc;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nullable;
import com.yandex.ydb.core.Issue;
import com.yandex.ydb.core.Result;
import com.yandex.ydb.core.StatusCode;
import io.grpc.ClientCall;
import io.grpc.Metadata;
import io.grpc.Status;
/**
* @author Sergey Polovko
*/
public class UnaryStreamToFuture extends ClientCall.Listener {
private final CompletableFuture> responseFuture;
private T value;
public UnaryStreamToFuture(CompletableFuture> responseFuture) {
this.responseFuture = responseFuture;
}
@Override
public void onMessage(T value) {
if (this.value != null) {
Issue issue = Issue.of("More than one value received for gRPC unary call", Issue.Severity.ERROR);
responseFuture.complete(Result.fail(StatusCode.CLIENT_INTERNAL_ERROR, issue));
}
this.value = value;
}
@Override
public void onClose(Status status, @Nullable Metadata trailers) {
if (status.isOk()) {
if (value == null) {
Issue issue = Issue.of("No value received for gRPC unary call", Issue.Severity.ERROR);
responseFuture.complete(Result.fail(StatusCode.CLIENT_INTERNAL_ERROR, issue));
} else {
responseFuture.complete(Result.success(value));
}
} else {
responseFuture.complete(GrpcStatuses.toResult(status));
}
}
}