public class ServerCalls
Helpers for implementing a gRPC server based on a Kotlin coroutine implementation.
public static ServerCalls INSTANCE
Helpers for implementing a gRPC server based on a Kotlin coroutine implementation.
@NotNull
public <RequestT,ResponseT> io.grpc.ServerMethodDefinition<RequestT,ResponseT> unaryServerMethodDefinition(@NotNull
kotlin.coroutines.CoroutineContext context,
@NotNull
io.grpc.MethodDescriptor<RequestT,ResponseT> descriptor,
@NotNull
kotlin.jvm.functions.Function2<? super RequestT,? super kotlin.coroutines.Continuation<? super ResponseT>,? extends java.lang.Object> implementation)
Creates a ServerMethodDefinition that implements the specified unary RPC method by running the specified implementation and associated implementation details within a per-RPC CoroutineScope generated with the specified CoroutineContext.
When the RPC is received, this method definition will pass the request from the client
to implementation, and send the response back to the client when it is returned.
If implementation fails with a StatusException, the RPC will fail with the corresponding
Status. If implementation fails with a CancellationException, the RPC will fail
with Status.CANCELLED. If implementation fails for any other reason, the RPC will
fail with Status.UNKNOWN with the exception as a cause. If a cancellation is received
from the client before implementation is complete, the coroutine will be cancelled and the
RPC will fail with Status.CANCELLED.
context - The context of the scopes the RPC implementation will run indescriptor - The descriptor of the method being implementedimplementation - The implementation of the RPC methodimplementation,
implementation,
implementation,
implementation,
implementation@NotNull
public <RequestT,ResponseT> io.grpc.ServerMethodDefinition<RequestT,ResponseT> clientStreamingServerMethodDefinition(@NotNull
kotlin.coroutines.CoroutineContext context,
@NotNull
io.grpc.MethodDescriptor<RequestT,ResponseT> descriptor,
@NotNull
kotlin.jvm.functions.Function2<? super kotlinx.coroutines.flow.Flow<? extends RequestT>,? super kotlin.coroutines.Continuation<? super ResponseT>,? extends java.lang.Object> implementation)
Creates a ServerMethodDefinition that implements the specified client-streaming RPC method by running the specified implementation and associated implementation details within a per-RPC CoroutineScope generated with the specified CoroutineContext.
When the RPC is received, this method definition will pass a Flow of requests from the client
to implementation, and send the response back to the client when it is returned.
Exceptions are handled as in unaryServerMethodDefinition. Additionally, attempts to collect
the requests flow more than once will throw an IllegalStateException, and if implementation
cancels collection of the requests flow, further requests from the client will be ignored
(and no backpressure will be applied).
context - The context of the scopes the RPC implementation will run indescriptor - The descriptor of the method being implementedimplementation - The implementation of the RPC methodimplementation,
unaryServerMethodDefinition,
IllegalStateException,
implementation@NotNull
public <RequestT,ResponseT> io.grpc.ServerMethodDefinition<RequestT,ResponseT> serverStreamingServerMethodDefinition(@NotNull
kotlin.coroutines.CoroutineContext context,
@NotNull
io.grpc.MethodDescriptor<RequestT,ResponseT> descriptor,
@NotNull
kotlin.jvm.functions.Function1<? super RequestT,? extends kotlinx.coroutines.flow.Flow<? extends ResponseT>> implementation)
Creates a ServerMethodDefinition that implements the specified server-streaming RPC method by
running the specified implementation and associated implementation details within a per-RPC
CoroutineScope generated with the specified CoroutineContext. When the RPC is received,
this method definition will collect the flow returned by implementation and send the emitted
values back to the client.
When the RPC is received, this method definition will pass the request from the client
to implementation, and collect the returned Flow, sending responses to the client as they
are emitted. Exceptions and cancellation are handled as in unaryServerMethodDefinition.
context - The context of the scopes the RPC implementation will run indescriptor - The descriptor of the method being implementedimplementation - The implementation of the RPC methodimplementation,
implementation,
unaryServerMethodDefinition@NotNull
public <RequestT,ResponseT> io.grpc.ServerMethodDefinition<RequestT,ResponseT> bidiStreamingServerMethodDefinition(@NotNull
kotlin.coroutines.CoroutineContext context,
@NotNull
io.grpc.MethodDescriptor<RequestT,ResponseT> descriptor,
@NotNull
kotlin.jvm.functions.Function1<? super kotlinx.coroutines.flow.Flow<? extends RequestT>,? extends kotlinx.coroutines.flow.Flow<? extends ResponseT>> implementation)
Creates a ServerMethodDefinition that implements the specified bidirectional-streaming RPC method by running the specified implementation and associated implementation details within a per-RPC CoroutineScope generated with the specified CoroutineContext.
When the RPC is received, this method definition will pass a Flow of requests from the client
to implementation, and collect the returned Flow, sending responses to the client as they
are emitted.
Exceptions and cancellation are handled as in clientStreamingServerMethodDefinition and as
in serverStreamingServerMethodDefinition.
context - The context of the scopes the RPC implementation will run indescriptor - The descriptor of the method being implementedimplementation - The implementation of the RPC methodimplementation,
clientStreamingServerMethodDefinition,
serverStreamingServerMethodDefinition