diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-02-16 00:47:34 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-02-16 00:47:34 +0100 |
commit | 55c3d369ecde5a3567e990104aa171ad8ee80874 (patch) | |
tree | bc7e0699ddd48c6099642d46cfd1a6b9bea183d8 /kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft | |
parent | 9623a6edcb96a24de8ded5c9a876a1a038c6ce1d (diff) | |
download | kvision-55c3d369ecde5a3567e990104aa171ad8ee80874.tar.gz kvision-55c3d369ecde5a3567e990104aa171ad8ee80874.tar.bz2 kvision-55c3d369ecde5a3567e990104aa171ad8ee80874.zip |
Refactor service manager for Jooby. Upgrade Jooby version to 1.6.0.
Diffstat (limited to 'kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft')
-rw-r--r-- | kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt | 33 |
1 files changed, 13 insertions, 20 deletions
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<T : Any> 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<T : Any> 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<PAR>(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<T : Any> 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<PAR1>(jsonRpcRequest.params[0]) val param2 = getParameter<PAR2>(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<T : Any> 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<PAR1>(jsonRpcRequest.params[0]) val param2 = getParameter<PAR2>(jsonRpcRequest.params[1]) val param3 = getParameter<PAR3>(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<T : Any> 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<PAR1>(jsonRpcRequest.params[0]) val param2 = getParameter<PAR2>(jsonRpcRequest.params[1]) val param3 = getParameter<PAR3>(jsonRpcRequest.params[2]) val param4 = getParameter<PAR4>(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<T : Any> 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<PAR1>(jsonRpcRequest.params[0]) @@ -299,6 +291,8 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: val param3 = getParameter<PAR3>(jsonRpcRequest.params[2]) val param4 = getParameter<PAR4>(jsonRpcRequest.params[3]) val param5 = getParameter<PAR5>(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<T : Any> 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<String?>(jsonRpcRequest.params[0]) val param2 = getParameter<String?>(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) |