From 55c3d369ecde5a3567e990104aa171ad8ee80874 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 16 Feb 2019 00:47:34 +0100 Subject: Refactor service manager for Jooby. Upgrade Jooby version to 1.6.0. --- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft') diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 3617463b..456bb901 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -70,9 +70,8 @@ actual open class KVServiceManager actual constructor(val serviceClass: } else { req.body(JsonRpcRequest::class.java) } - val service = req.require(serviceClass.java) val injector = req.require(Injector::class.java) - injector.injectMembers(service) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service) @@ -108,11 +107,10 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(method, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) if (jsonRpcRequest.params.size == 1) { val param = getParameter(jsonRpcRequest.params[0]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param) @@ -151,12 +149,11 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(method, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) if (jsonRpcRequest.params.size == 2) { val param1 = getParameter(jsonRpcRequest.params[0]) val param2 = getParameter(jsonRpcRequest.params[1]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param1, param2) @@ -195,14 +192,13 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(method, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) @Suppress("MagicNumber") if (jsonRpcRequest.params.size == 3) { val param1 = getParameter(jsonRpcRequest.params[0]) val param2 = getParameter(jsonRpcRequest.params[1]) val param3 = getParameter(jsonRpcRequest.params[2]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param1, param2, param3) @@ -241,15 +237,14 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(method, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) @Suppress("MagicNumber") if (jsonRpcRequest.params.size == 4) { val param1 = getParameter(jsonRpcRequest.params[0]) val param2 = getParameter(jsonRpcRequest.params[1]) val param3 = getParameter(jsonRpcRequest.params[2]) val param4 = getParameter(jsonRpcRequest.params[3]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param1, param2, param3, param4) @@ -289,9 +284,6 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(method, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) @Suppress("MagicNumber") if (jsonRpcRequest.params.size == 5) { val param1 = getParameter(jsonRpcRequest.params[0]) @@ -299,6 +291,8 @@ actual open class KVServiceManager actual constructor(val serviceClass: val param3 = getParameter(jsonRpcRequest.params[2]) val param4 = getParameter(jsonRpcRequest.params[3]) val param5 = getParameter(jsonRpcRequest.params[4]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param1, param2, param3, param4, param5) @@ -332,12 +326,11 @@ actual open class KVServiceManager actual constructor(val serviceClass: routes.add { call(HttpMethod.POST, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - val service = req.require(serviceClass.java) - val injector = req.require(Injector::class.java) - injector.injectMembers(service) if (jsonRpcRequest.params.size == 2) { val param1 = getParameter(jsonRpcRequest.params[0]) val param2 = getParameter(jsonRpcRequest.params[1]) + val injector = req.require(Injector::class.java) + val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { val result = function.invoke(service, param1, param2) -- cgit