Skip to content

Commit

Permalink
Update set up for ScheduledExecutorService.
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasankavitha committed Nov 4, 2023
1 parent e726e3b commit 1558831
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.web.context.request.WebRequest
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService

/**
* Framework auto configuration based on open source Spring only, without Netflix integrations.
Expand Down Expand Up @@ -154,8 +156,14 @@ open class DgsAutoConfiguration(
}

@Bean
open fun dgsDataLoaderProvider(applicationContext: ApplicationContext, dataloaderOptionProvider: DgsDataLoaderOptionsProvider): DgsDataLoaderProvider {
return DgsDataLoaderProvider(applicationContext, dataloaderOptionProvider)
@ConditionalOnMissingBean
open fun scheduledExecutorService(): ScheduledExecutorService {
return Executors.newSingleThreadScheduledExecutor()
}

@Bean
open fun dgsDataLoaderProvider(applicationContext: ApplicationContext, dataloaderOptionProvider: DgsDataLoaderOptionsProvider, scheduledExecutorService: ScheduledExecutorService): DgsDataLoaderProvider {
return DgsDataLoaderProvider(applicationContext, dataloaderOptionProvider, scheduledExecutorService)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import org.springframework.boot.context.properties.bind.DefaultValue
data class DgsConfigurationProperties(
/** Location of the GraphQL schema files. */
@DefaultValue(DEFAULT_SCHEMA_LOCATION) val schemaLocations: List<String>,
@DefaultValue("true") val schemaWiringValidationEnabled: Boolean
@DefaultValue("true") val schemaWiringValidationEnabled: Boolean,
/** Data loader properties.*/
@DefaultValue("false") val dataloaderTickerMode: Boolean
) {
companion object {
const val PREFIX: String = "dgs.graphql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import org.springframework.aop.support.AopUtils
import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.context.ApplicationContext
import org.springframework.util.ReflectionUtils
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.function.Supplier
import kotlin.system.measureTimeMillis

Expand All @@ -46,7 +48,8 @@ import kotlin.system.measureTimeMillis
*/
class DgsDataLoaderProvider(
private val applicationContext: ApplicationContext,
private val dataLoaderOptionsProvider: DgsDataLoaderOptionsProvider = DefaultDataLoaderOptionsProvider()
private val dataLoaderOptionsProvider: DgsDataLoaderOptionsProvider = DefaultDataLoaderOptionsProvider(),
private val scheduledExecutorService: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor()
) {

private data class LoaderHolder<T>(val theLoader: T, val annotation: DgsDataLoader, val name: String, val dispatchPredicate: DispatchPredicate? = null)
Expand All @@ -63,7 +66,9 @@ class DgsDataLoaderProvider(
}

fun <T> buildRegistryWithContextSupplier(contextSupplier: Supplier<T>): DataLoaderRegistry {
val registry = ScheduledDataLoaderRegistry.newScheduledRegistry().dispatchPredicate(DispatchPredicate.DISPATCH_NEVER).build()
val tickerMode = applicationContext.environment.getProperty("dgs.graphql.dataloaderTickerMode").toBoolean()
val registry = ScheduledDataLoaderRegistry.newScheduledRegistry().scheduledExecutorService(scheduledExecutorService).tickerMode(tickerMode).dispatchPredicate(DispatchPredicate.DISPATCH_NEVER).build()

val totalTime = measureTimeMillis {
val extensionProviders = applicationContext
.getBeanProvider(DataLoaderInstrumentationExtensionProvider::class.java)
Expand Down

0 comments on commit 1558831

Please sign in to comment.