Skip to content

Commit

Permalink
Add polish to coroutine support in RESTEasy Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed May 8, 2021
1 parent 0d46d8e commit e91bc43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ApplicationCoroutineScope : CoroutineScope, AutoCloseable {
}

/**
* Dispatches the coroutine in a worker thread from Vertx.
* Dispatches the coroutine in Vertx IO thread.
*/
class VertxDispatcher(private val vertxContext: Context) : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
Expand All @@ -33,4 +33,4 @@ class VertxDispatcher(private val vertxContext: Context) : CoroutineDispatcher()
block.run()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import org.jboss.resteasy.reactive.server.spi.EndpointInvoker
/**
* Base interface implemented by the synthetic beans that represent suspending rest endpoints.
*
* @see [KotlinCoroutineIntegrationProcessor]
* @see [EndpointInvoker]
*
* Also see io.quarkus.resteasy.reactive.server.deployment.KotlinCoroutineIntegrationProcessor for the build-time part
* of coroutine support
*/
interface CoroutineEndpointInvoker: EndpointInvoker {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CoroutineInvocationHandler(private val invoker: EndpointInvoker,
val dispatcher: CoroutineDispatcher = Vertx.currentContext()?.let(::VertxDispatcher)
?: throw IllegalStateException("No Vertx context found")

logger.debug("Handling request with dispatcher {}", dispatcher)
logger.trace("Handling request with dispatcher {}", dispatcher)

requestContext.requireCDIRequestScope()
requestContext.suspend()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.jboss.resteasy.reactive.server.runtime.kotlin

import io.quarkus.arc.Unremovable
import org.jboss.resteasy.reactive.server.spi.EndpointInvoker
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
import javax.inject.Singleton

/**
* Factory for the [CoroutineInvocationHandler] that is already part of the CDI container
*/
@ApplicationScoped
class CoroutineInvocationHandlerFactory @Inject constructor(
private val applicationCoroutineScope: ApplicationCoroutineScope
) {
@Singleton
@Unremovable
class CoroutineInvocationHandlerFactory(private val applicationCoroutineScope: ApplicationCoroutineScope) {
fun createHandler(invoker: EndpointInvoker): ServerRestHandler {
return CoroutineInvocationHandler(invoker, applicationCoroutineScope)
}
}
}

0 comments on commit e91bc43

Please sign in to comment.