marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Apache License 2.0
493 stars 28 forks source link

Refactor server calls to implement ServerCallHandler #79

Open marcoferrer opened 5 years ago

marcoferrer commented 5 years ago

Currently server implementations use server handler builder to process incoming calls using the existing stream observer api. This requires a lot of adapter code just to map coroutine behavior to the existing stream observer call back.

It should be possible to implement ServerCallHandler and emit its usage in the generated code. This gives us the ability to not only improve performance but map the coroutine apis closer to the call level.

At the moment it is difficult to expand the kroto API. With access to the call, we could potentially allow users to pass execution parameters via a call wrapper type. This would allow the customization of the following:

Call wrapper example:

abstract class ServerCallCoroutine<ReqT,RespT>(
    delegate: ServerCall<ReqT,RespT>
) : SimpleForwardingServerCall<ReqT,RespT>(delegate){

    open val initialContext: CoroutineContext = EmptyCoroutineContext

    open val coroutineStart: CoroutineStart = CoroutineStart.ATOMIC

    open val requestChannelBufferSize: Int = Channel.BUFFER

}

The kroto implementation of ServerCallHandler would be able to check for this type explicitly during method invocation and use the parameters provided