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

grpc.cache_client.pubsub.CachepubsubGrpcKt.kt Maven / Gradle / Ivy

There is a newer version: 0.119.4
Show newest version
package grpc.cache_client.pubsub

import grpc.cache_client.pubsub.PubsubGrpc.getServiceDescriptor
import grpc.common._Empty
import io.grpc.CallOptions
import io.grpc.CallOptions.DEFAULT
import io.grpc.Channel
import io.grpc.Metadata
import io.grpc.MethodDescriptor
import io.grpc.ServerServiceDefinition
import io.grpc.ServerServiceDefinition.builder
import io.grpc.ServiceDescriptor
import io.grpc.Status.UNIMPLEMENTED
import io.grpc.StatusException
import io.grpc.kotlin.AbstractCoroutineServerImpl
import io.grpc.kotlin.AbstractCoroutineStub
import io.grpc.kotlin.ClientCalls.serverStreamingRpc
import io.grpc.kotlin.ClientCalls.unaryRpc
import io.grpc.kotlin.ServerCalls.serverStreamingServerMethodDefinition
import io.grpc.kotlin.ServerCalls.unaryServerMethodDefinition
import io.grpc.kotlin.StubFor
import kotlin.String
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic
import kotlinx.coroutines.flow.Flow

/**
 * Holder for Kotlin coroutine-based client and server APIs for cache_client.pubsub.Pubsub.
 */
public object PubsubGrpcKt {
  public const val SERVICE_NAME: String = PubsubGrpc.SERVICE_NAME

  @JvmStatic
  public val serviceDescriptor: ServiceDescriptor
    get() = getServiceDescriptor()

  public val publishMethod: MethodDescriptor<_PublishRequest, _Empty>
    @JvmStatic
    get() = PubsubGrpc.getPublishMethod()

  public val subscribeMethod: MethodDescriptor<_SubscriptionRequest, _SubscriptionItem>
    @JvmStatic
    get() = PubsubGrpc.getSubscribeMethod()

  /**
   * A stub for issuing RPCs to a(n) cache_client.pubsub.Pubsub service as suspending coroutines.
   */
  @StubFor(PubsubGrpc::class)
  public class PubsubCoroutineStub @JvmOverloads constructor(
    channel: Channel,
    callOptions: CallOptions = DEFAULT,
  ) : AbstractCoroutineStub(channel, callOptions) {
    override fun build(channel: Channel, callOptions: CallOptions): PubsubCoroutineStub =
        PubsubCoroutineStub(channel, callOptions)

    /**
     * Executes this RPC and returns the response message, suspending until the RPC completes
     * with [`Status.OK`][io.grpc.Status].  If the RPC completes with another status, a
     * corresponding
     * [StatusException] is thrown.  If this coroutine is cancelled, the RPC is also cancelled
     * with the corresponding exception as a cause.
     *
     * @param request The request message to send to the server.
     *
     * @param headers Metadata to attach to the request.  Most users will not need this.
     *
     * @return The single response from the server.
     */
    public suspend fun publish(request: _PublishRequest, headers: Metadata = Metadata()): _Empty =
        unaryRpc(
      channel,
      PubsubGrpc.getPublishMethod(),
      request,
      callOptions,
      headers
    )

    /**
     * Returns a [Flow] that, when collected, executes this RPC and emits responses from the
     * server as they arrive.  That flow finishes normally if the server closes its response with
     * [`Status.OK`][io.grpc.Status], and fails by throwing a [StatusException] otherwise.  If
     * collecting the flow downstream fails exceptionally (including via cancellation), the RPC
     * is cancelled with that exception as a cause.
     *
     * @param request The request message to send to the server.
     *
     * @param headers Metadata to attach to the request.  Most users will not need this.
     *
     * @return A flow that, when collected, emits the responses from the server.
     */
    public fun subscribe(request: _SubscriptionRequest, headers: Metadata = Metadata()):
        Flow<_SubscriptionItem> = serverStreamingRpc(
      channel,
      PubsubGrpc.getSubscribeMethod(),
      request,
      callOptions,
      headers
    )
  }

  /**
   * Skeletal implementation of the cache_client.pubsub.Pubsub service based on Kotlin coroutines.
   */
  public abstract class PubsubCoroutineImplBase(
    coroutineContext: CoroutineContext = EmptyCoroutineContext,
  ) : AbstractCoroutineServerImpl(coroutineContext) {
    /**
     * Returns the response to an RPC for cache_client.pubsub.Pubsub.Publish.
     *
     * If this method fails with a [StatusException], the RPC will fail with the corresponding
     * [io.grpc.Status].  If this method fails with a [java.util.concurrent.CancellationException],
     * the RPC will fail
     * with status `Status.CANCELLED`.  If this method fails for any other reason, the RPC will
     * fail with `Status.UNKNOWN` with the exception as a cause.
     *
     * @param request The request from the client.
     */
    public open suspend fun publish(request: _PublishRequest): _Empty = throw
        StatusException(UNIMPLEMENTED.withDescription("Method cache_client.pubsub.Pubsub.Publish is unimplemented"))

    /**
     * Returns a [Flow] of responses to an RPC for cache_client.pubsub.Pubsub.Subscribe.
     *
     * If creating or collecting the returned flow fails with a [StatusException], the RPC
     * will fail with the corresponding [io.grpc.Status].  If it fails with a
     * [java.util.concurrent.CancellationException], the RPC will fail with status
     * `Status.CANCELLED`.  If creating
     * or collecting the returned flow fails for any other reason, the RPC will fail with
     * `Status.UNKNOWN` with the exception as a cause.
     *
     * @param request The request from the client.
     */
    public open fun subscribe(request: _SubscriptionRequest): Flow<_SubscriptionItem> = throw
        StatusException(UNIMPLEMENTED.withDescription("Method cache_client.pubsub.Pubsub.Subscribe is unimplemented"))

    final override fun bindService(): ServerServiceDefinition = builder(getServiceDescriptor())
      .addMethod(unaryServerMethodDefinition(
      context = this.context,
      descriptor = PubsubGrpc.getPublishMethod(),
      implementation = ::publish
    ))
      .addMethod(serverStreamingServerMethodDefinition(
      context = this.context,
      descriptor = PubsubGrpc.getSubscribeMethod(),
      implementation = ::subscribe
    )).build()
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy