diff --git a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/event/CoroutineListener.kt b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/event/CoroutineListener.kt index b0bbb9e..0fb4958 100644 --- a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/event/CoroutineListener.kt +++ b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/event/CoroutineListener.kt @@ -26,13 +26,13 @@ import org.springframework.stereotype.Component @Component open class CoroutineListener { @EventListener - suspend open fun handle(event: SimpleEvent) { + open suspend fun handle(event: SimpleEvent) { delay(10) logger.info ("Received event $event") } @EventListener - suspend open fun handleDemoEvent(event: DemoApplicationEvent) { + open suspend fun handleDemoEvent(event: DemoApplicationEvent) { delay(10) logger.info ("Received demoEvent $event") } diff --git a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/service/DemoService.kt b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/service/DemoService.kt index fa0eae3..50311be 100644 --- a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/service/DemoService.kt +++ b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/service/DemoService.kt @@ -27,16 +27,16 @@ import org.springframework.stereotype.Component @Component open class DemoService { @Scheduled(cron = "0 0 0 1 1 *") - suspend open fun newYear() { + open suspend fun newYear() { logger.info("Happy New Year!") } @Scheduled(fixedRate = 60_000) - suspend open fun everyMinute() { + open suspend fun everyMinute() { logger.info("I'm still alive...") } - suspend open fun delayedReturn(s: String, delayMillis: Long): String { + open suspend fun delayedReturn(s: String, delayMillis: Long): String { logger.info ("Before delay in [delayedReturn]") delay(delayMillis) logger.info ("After delay in [delayedReturn]") @@ -45,14 +45,14 @@ open class DemoService { } @Coroutine(DEFAULT_DISPATCHER) - suspend open fun defaultDispatcherReturn(s: String): String { + open suspend fun defaultDispatcherReturn(s: String): String { logger.info ("In [defaultDispatcher]") return s } @Cacheable("cache1") - suspend open fun cachedDelayedReturn(s: String, delayMillis: Long): String { + open suspend fun cachedDelayedReturn(s: String, delayMillis: Long): String { logger.info ("Before delay in [cachedDelayedReturn]") delay(delayMillis) logger.info ("After delay in [cachedDelayedReturn]") @@ -62,7 +62,7 @@ open class DemoService { @Cacheable("cache2") @Coroutine(DEFAULT_DISPATCHER) - suspend open fun cachedDefaultDispatcherDelayedReturn(s: String, delayMillis: Long): String { + open suspend fun cachedDefaultDispatcherDelayedReturn(s: String, delayMillis: Long): String { logger.info ("Before delay in [cachedDefaultDispatcherDelayedReturn]") delay(delayMillis) logger.info ("After delay in [cachedDefaultDispatcherDelayedReturn]") diff --git a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/web/DemoController.kt b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/web/DemoController.kt index e71348c..cead820 100644 --- a/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/web/DemoController.kt +++ b/spring-kotlin-coroutine-demo/src/main/kotlin/demo/app/web/DemoController.kt @@ -37,7 +37,7 @@ open class DemoController( private val restOperations = CoroutineRestOperations() @GetMapping("/delayed") - suspend open fun delayedReturn(): String { + open suspend fun delayedReturn(): String { logger.info ("Before call to [demoService.delayed]") val result = demoService.delayedReturn("delayed", 1000) logger.info ("After call to [demoService.delayed]") @@ -46,7 +46,7 @@ open class DemoController( } @GetMapping("/defaultDispatcher") - suspend open fun defaultDispatcherReturn(): String { + open suspend fun defaultDispatcherReturn(): String { logger.info ("Before call to [demoService.defaultDispatcherReturn]") val result = demoService.defaultDispatcherReturn("defaultDispatcher") logger.info ("After call to [demoService.defaultDispatcherReturn]") @@ -55,7 +55,7 @@ open class DemoController( } @GetMapping("/cachedDelayed") - suspend open fun cachedDelayedReturn(): String { + open suspend fun cachedDelayedReturn(): String { logger.info ("Before call to [demoService.cachedDelayedReturn]") val result = demoService.cachedDelayedReturn("cachedDelayed", 500) logger.info ("After call to [demoService.cachedDelayedReturn]") @@ -64,7 +64,7 @@ open class DemoController( } @GetMapping("/cachedDefaultDispatcherDelayed") - suspend open fun cachedDefaultDispatcherDelayed(): String { + open suspend fun cachedDefaultDispatcherDelayed(): String { logger.info ("Before call to [demoService.cachedDefaultDispatcherDelayedReturn]") val result = demoService.cachedDefaultDispatcherDelayedReturn("cachedDefaultDsipatcherDelayed", 1500) logger.info ("After call to [demoService.cachedDefaultDeispatcherDelayedReturn]") @@ -74,14 +74,14 @@ open class DemoController( @GetMapping("/defaultDispatcherController") @Coroutine(DEFAULT_DISPATCHER) - suspend open fun defaultDispatcherController(): String { + open suspend fun defaultDispatcherController(): String { logger.info ("In [defaultDispatcherController]") return "defaultDispatcherController" } @GetMapping("/event") - suspend open fun event(): String { + open suspend fun event(): String { publisher.publishEvent(SimpleEvent("Hello")) publisher.publishEvent(DemoApplicationEvent(this, "Hello")) coroutinePublisher.publishEvent(SimpleEvent("Hello-coroutine")) @@ -91,7 +91,7 @@ open class DemoController( } @GetMapping("/rest") - suspend open fun rest(request: HttpServletRequest): String { + open suspend fun rest(request: HttpServletRequest): String { logger.info ("Before call to [restOperations.getForEntity]") val result = restOperations.getForEntity(request.requestURL.toString().replace("rest", "delayed"), String::class.java) logger.info ("After call to [restOperations.getForEntity]") @@ -108,7 +108,7 @@ open class DemoController( open class DemoApplicationEvent( source: Any, - val message: String + private val message: String ): ApplicationEvent(source) { override fun toString(): String = "DemoApplicationEvent(source=$source, message=$message)"