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

com.yandex.ydb.core.grpc.GrpcDiscoveryRpc Maven / Gradle / Ivy

There is a newer version: 1.45.6
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy