games.mythical.saga.sdk.proto.streams.StreamGrpcKt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of saga-sdk-proto Show documentation
Show all versions of saga-sdk-proto Show documentation
Saga SDK for Java game servers
package games.mythical.saga.sdk.proto.streams
import com.google.protobuf.Empty
import games.mythical.saga.sdk.proto.streams.StatusStreamGrpc.getServiceDescriptor
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
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 saga.rpc.streams.StatusStream.
*/
object StatusStreamGrpcKt {
const val SERVICE_NAME: String = StatusStreamGrpc.SERVICE_NAME
@JvmStatic
val serviceDescriptor: ServiceDescriptor
get() = StatusStreamGrpc.getServiceDescriptor()
val statusStreamMethod: MethodDescriptor
@JvmStatic
get() = StatusStreamGrpc.getStatusStreamMethod()
val statusConfirmationMethod: MethodDescriptor
@JvmStatic
get() = StatusStreamGrpc.getStatusConfirmationMethod()
/**
* A stub for issuing RPCs to a(n) saga.rpc.streams.StatusStream service as suspending coroutines.
*/
@StubFor(StatusStreamGrpc::class)
class StatusStreamCoroutineStub @JvmOverloads constructor(
channel: Channel,
callOptions: CallOptions = DEFAULT
) : AbstractCoroutineStub(channel, callOptions) {
override fun build(channel: Channel, callOptions: CallOptions): StatusStreamCoroutineStub =
StatusStreamCoroutineStub(channel, callOptions)
/**
* 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`][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.
*/
fun statusStream(request: Subscribe, headers: Metadata = Metadata()): Flow =
serverStreamingRpc(
channel,
StatusStreamGrpc.getStatusStreamMethod(),
request,
callOptions,
headers
)
/**
* Executes this RPC and returns the response message, suspending until the RPC completes
* with [`Status.OK`][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.
*/
suspend fun statusConfirmation(request: StatusConfirmRequest, headers: Metadata = Metadata()):
Empty = unaryRpc(
channel,
StatusStreamGrpc.getStatusConfirmationMethod(),
request,
callOptions,
headers
)}
/**
* Skeletal implementation of the saga.rpc.streams.StatusStream service based on Kotlin
* coroutines.
*/
abstract class StatusStreamCoroutineImplBase(
coroutineContext: CoroutineContext = EmptyCoroutineContext
) : AbstractCoroutineServerImpl(coroutineContext) {
/**
* Returns a [Flow] of responses to an RPC for saga.rpc.streams.StatusStream.StatusStream.
*
* If creating or collecting the returned flow fails with a [StatusException], the RPC
* will fail with the corresponding [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.
*/
open fun statusStream(request: Subscribe): Flow = throw
StatusException(UNIMPLEMENTED.withDescription("Method saga.rpc.streams.StatusStream.StatusStream is unimplemented"))
/**
* Returns the response to an RPC for saga.rpc.streams.StatusStream.StatusConfirmation.
*
* If this method fails with a [StatusException], the RPC will fail with the corresponding
* [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.
*/
open suspend fun statusConfirmation(request: StatusConfirmRequest): Empty = throw
StatusException(UNIMPLEMENTED.withDescription("Method saga.rpc.streams.StatusStream.StatusConfirmation is unimplemented"))
final override fun bindService(): ServerServiceDefinition = builder(getServiceDescriptor())
.addMethod(serverStreamingServerMethodDefinition(
context = this.context,
descriptor = StatusStreamGrpc.getStatusStreamMethod(),
implementation = ::statusStream
))
.addMethod(unaryServerMethodDefinition(
context = this.context,
descriptor = StatusStreamGrpc.getStatusConfirmationMethod(),
implementation = ::statusConfirmation
)).build()
}
}