com.yandex.ydb.core.grpc.GrpcDiscoveryRpc 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 java.util.function.Function;
import com.yandex.ydb.core.Result;
import com.yandex.ydb.core.rpc.OperationTray;
import com.yandex.ydb.discovery.DiscoveryProtos.ListEndpointsRequest;
import com.yandex.ydb.discovery.DiscoveryProtos.ListEndpointsResult;
import com.yandex.ydb.discovery.v1.DiscoveryServiceGrpc;
/**
* @author Vladimir Gordiychuk
*/
public class GrpcDiscoveryRpc implements AutoCloseable {
private final GrpcTransport transport;
private final OperationTray operationTray;
public GrpcDiscoveryRpc(GrpcTransport transport) {
this.transport = transport;
this.operationTray = transport.getOperationTray();
}
public CompletableFuture> listEndpoints(String database, long deadlineAfter) {
ListEndpointsRequest request = ListEndpointsRequest.newBuilder()
.setDatabase(database)
.build();
return transport.unaryCall(DiscoveryServiceGrpc.getListEndpointsMethod(), request, deadlineAfter)
.thenCompose(result -> {
if (!result.isSuccess()) {
return CompletableFuture.completedFuture(result.cast());
}
return operationTray.waitResult(
result.expect("listEndpoints()").getOperation(),
ListEndpointsResult.class,
Function.identity(),
deadlineAfter);
});
}
@Override
public void close() {
transport.close();
}
}