Skip to content

Commit

Permalink
update docs for ServiceScope
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoferrer committed Mar 14, 2019
1 parent 4507c45 commit 4d33be7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _2018-\*\*-\*\*_
* Fix: Remove unnecessary creation of `CoroutineScope` in `newSendChannelFromObserver`
* New: Introduce `ServiceScope` interface and remove `CoroutineScope` from generated service classes
* New: Use `Message.getDefaultInstance()` as default value of stub request parameters
* New: Increased code coverage across the board
* Deprecated: Legacy service stub rpc builders in favor of new back-pressure supporting stub APIs

#### gRPC Stub Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,46 @@

package com.github.marcoferrer.krotoplus.coroutines.server

import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext


/**
* Defines a scope for gRPC service implementations. The generated abstract base class for every gRPC coroutine service
* implements this interface. This interface allows service implementations to define the initial [CoroutineContext]
* that will be used to populate a new [CoroutineScope] for each incoming rpc method invocation.
*
* Usage of this interface from within service implementations may look like this:
*
* ```
* // GreeterCoroutineGrpc.GreeterImplBase implements the [ServiceScope] interface
*
* class GreeterServiceImpl : GreeterCoroutineGrpc.GreeterImplBase() {
*
* // Attach the thread local logging context (which was initially setup up in a server interceptor)
* // for every new rpc invocation.
* val initialContext: CoroutineContext
* get() = Dispatchers.Default + MDCContext()
*
* suspend fun sayHello(request: HelloRequest): HelloReply {
* ...
* }
* }
* ```
*
* Details showing usage during server rpc invocation at:
* - Unary RPCs: [ServiceScope.serverCallUnary]
* - Client Streaming RPCs: [ServiceScope.serverCallClientStreaming]
* - Server Streaming RPCs: [ServiceScope.serverCallServerStreaming]
* - Bidirectional RPCs: [ServiceScope.serverCallBidiStreaming]
*
*/
interface ServiceScope {

/**
* The context that will be used to create a new [CoroutineScope] for
* every incoming rpc request.
*/
val initialContext: CoroutineContext

}

0 comments on commit 4d33be7

Please sign in to comment.