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

build.bazel.remote.execution.v2.CapabilitiesClient.kt Maven / Gradle / Ivy

package build.bazel.remote.execution.v2

import com.google.api.kgax.Retry
import com.google.api.kgax.grpc.ClientCallOptions
import com.google.api.kgax.grpc.ClientCallOptions.Builder
import com.google.api.kgax.grpc.GrpcBasicRetry
import com.google.api.kgax.grpc.GrpcClientStub
import com.google.api.kgax.grpc.pager
import com.google.api.kgax.grpc.prepare
import com.google.longrunning.OperationsClientStub
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import java.util.concurrent.TimeUnit
import javax.annotation.Generated
import kotlin.Boolean
import kotlin.Int
import kotlin.Long
import kotlin.String
import kotlin.Unit
import kotlin.collections.List
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope

/**
 *
 *
 *
 *
 * [Product Documentation](http://www.google.com)
 */
@Generated("com.google.api.kotlin.generator.GRPCGenerator")
class CapabilitiesClient private constructor(
    val channel: ManagedChannel,
    val options: ClientCallOptions,
    factory: Stubs.Factory? = null
) {
    private val stubs: Stubs = factory?.create(channel, options) ?: Stubs(
            CapabilitiesClientStub(channel).prepare(options),
            OperationsClientStub(channel).prepare(options))

    /**
     * Prepare for an API call by setting any desired options. For example:
     *
     * ```
     * val client = CapabilitiesClient.create()
     * val response = client.prepare {
     *     withMetadata("my-custom-header", listOf("some", "thing"))
     * }.getCapabilities(request)
     * ```
     *
     * You may save the client returned by this call and reuse it if you
     * plan to make multiple requests with the same settings.
     */
    fun prepare(init: ClientCallOptions.Builder.() -> Unit): CapabilitiesClient {
        val optionsBuilder = ClientCallOptions.Builder(options)
        optionsBuilder.init()
        return CapabilitiesClient(channel, optionsBuilder.build())
    }

    /**
     * Shutdown the [channel] associated with this client.
     */
    fun shutdownChannel(waitForSeconds: Long = 5) {
        channel.shutdown().awaitTermination(waitForSeconds, TimeUnit.SECONDS)
    }

    /**
     * GetCapabilities returns the server capabilities configuration of the
     * remote endpoint.
     * Only the capabilities of the services supported by the endpoint will
     * be returned:
     * * Execution + CAS + Action Cache endpoints should return both
     *   CacheCapabilities and ExecutionCapabilities.
     * * Execution only endpoints should return ExecutionCapabilities.
     * * CAS + Action Cache only endpoints should return CacheCapabilities.
     *
     * For example:
     * ```
     * val client = CapabilitiesClient.create()
     * val result = client.getCapabilities(
     *     getCapabilitiesRequest {
     *     }
     * )
     * ```
     *
     * @param request the request object for the API call
     */
    suspend fun getCapabilities(request: GetCapabilitiesRequest): ServerCapabilities =
            stubs.api.execute(context = "getCapabilities") {
        it.getCapabilities(request)
    }

    /**
     * Utilities for creating a fully configured CapabilitiesClient.
     */
    companion object {
        /**
         * Default scopes to use. Use [prepare] to override as needed.
         */
        @JvmStatic
        val ALL_SCOPES: List = listOf()

        /**
         * Default operations to retry on failure. Use [prepare] to override as needed.
         *
         * Note: This setting controls client side retries. If you enable
         * server managed retries on the channel do not use this.
         */
        @JvmStatic
        val RETRY: Retry = GrpcBasicRetry(mapOf())

        /**
         * Create a CapabilitiesClient with the provided [channel], [options], or stub [factory].
         */
        @JvmStatic
        @JvmOverloads
        fun create(
            channel: ManagedChannel? = null,
            options: ClientCallOptions? = null,
            factory: Stubs.Factory? = null
        ): CapabilitiesClient = CapabilitiesClient(
            channel ?: createChannel(),
            options ?: ClientCallOptions(),
            factory
        )

        /**
         * Create a [ManagedChannel] to use with a CapabilitiesClient.
         *
         * [enableRetry] can be used to enable server managed retries, which is currently
         * experimental. You should not use any client retry settings if you enable it.
         */
        @JvmStatic
        @JvmOverloads
        fun createChannel(
            host: String = "",
            port: Int = 443,
            enableRetry: Boolean = false
        ): ManagedChannel {
            val builder = ManagedChannelBuilder.forAddress(host, port)
            if (enableRetry) {
                builder.enableRetry()
            }
            return builder.build()
        }
    }

    class Stubs(val api: GrpcClientStub, val operation:
            GrpcClientStub) {
        interface Factory {
            fun create(channel: ManagedChannel, options: ClientCallOptions): Stubs
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy