From 062b8a76ae21af17cd4b8fd3e5c220d544eff5e8 Mon Sep 17 00:00:00 2001 From: Robinson Date: Thu, 2 Mar 2023 19:44:06 +0100 Subject: [PATCH] updated API --- src/dorkbox/network/handshake/ServerHandshake.kt | 2 +- src/dorkbox/network/ping/PingManager.kt | 4 ++-- src/dorkbox/network/rmi/ResponseManager.kt | 7 +++---- src/dorkbox/network/rmi/RmiClient.kt | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dorkbox/network/handshake/ServerHandshake.kt b/src/dorkbox/network/handshake/ServerHandshake.kt index b03ab547..3b1a4487 100644 --- a/src/dorkbox/network/handshake/ServerHandshake.kt +++ b/src/dorkbox/network/handshake/ServerHandshake.kt @@ -82,7 +82,7 @@ internal class ServerHandshake( // note: CANNOT be called in action dispatch. ALWAYS ON SAME THREAD. ONLY RESPONSES ARE ON ACTION DISPATCH! private fun validateMessageTypeAndDoPending( server: Server, - eventDispatch: CoroutineScope, + eventDispatch: EventDispatcher, handshakePublication: Publication, message: HandshakeMessage, logger: KLogger diff --git a/src/dorkbox/network/ping/PingManager.kt b/src/dorkbox/network/ping/PingManager.kt index 5a88c8df..6472e7a0 100644 --- a/src/dorkbox/network/ping/PingManager.kt +++ b/src/dorkbox/network/ping/PingManager.kt @@ -20,8 +20,8 @@ package dorkbox.network.ping import dorkbox.network.connection.Connection +import dorkbox.network.connection.EventDispatcher import dorkbox.network.rmi.ResponseManager -import kotlinx.coroutines.CoroutineScope import mu.KLogger import java.util.concurrent.* @@ -61,7 +61,7 @@ internal class PingManager { internal suspend fun ping( connection: Connection, pingTimeoutSeconds: Int, - eventDispatch: CoroutineScope, + eventDispatch: EventDispatcher, responseManager: ResponseManager, logger: KLogger, function: suspend Ping.() -> Unit diff --git a/src/dorkbox/network/rmi/ResponseManager.kt b/src/dorkbox/network/rmi/ResponseManager.kt index 6aaebdb3..6b7e7f1f 100644 --- a/src/dorkbox/network/rmi/ResponseManager.kt +++ b/src/dorkbox/network/rmi/ResponseManager.kt @@ -16,12 +16,11 @@ package dorkbox.network.rmi import dorkbox.network.connection.Connection +import dorkbox.network.connection.EventDispatcher import kotlinx.atomicfu.atomic -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.ClosedSendChannelException import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import mu.KLogger import mu.KotlinLogging @@ -184,7 +183,7 @@ internal class ResponseManager(maxValuesInCache: Int = 65535, minimumValue: Int /** * Cancels the RMI request in the given timeout, the callback is executed inside the read lock */ - fun cancelRequest(eventDispatch: CoroutineScope, timeoutMillis: Long, id: Int, logger: KLogger, onCancelled: ResponseWaiter.() -> Unit) { + fun cancelRequest(eventDispatch: EventDispatcher, timeoutMillis: Long, id: Int, logger: KLogger, onCancelled: ResponseWaiter.() -> Unit) { eventDispatch.launch { delay(timeoutMillis) // this will always wait. if this job is cancelled, this will immediately stop waiting @@ -209,7 +208,7 @@ internal class ResponseManager(maxValuesInCache: Int = 65535, minimumValue: Int * @return the result (can be null) or timeout exception */ suspend fun waitForReply( - eventDispatch: CoroutineScope, + eventDispatch: EventDispatcher, responseWaiter: ResponseWaiter, timeoutMillis: Long, logger: KLogger, diff --git a/src/dorkbox/network/rmi/RmiClient.kt b/src/dorkbox/network/rmi/RmiClient.kt index c05fedc5..7f27167f 100644 --- a/src/dorkbox/network/rmi/RmiClient.kt +++ b/src/dorkbox/network/rmi/RmiClient.kt @@ -17,8 +17,8 @@ package dorkbox.network.rmi import dorkbox.network.connection.Connection import dorkbox.network.connection.EndPoint +import dorkbox.network.connection.EventDispatcher import dorkbox.network.rmi.messages.MethodRequest -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.asContextElement import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext @@ -181,7 +181,7 @@ internal class RmiClient(val isGlobal: Boolean, @Volatile private var enableEquals = false // if we are ASYNC, then this method immediately returns - private suspend fun sendRequest(isAsync: Boolean, eventDispatch: CoroutineScope, invokeMethod: MethodRequest, logger: KLogger): Any? { + private suspend fun sendRequest(isAsync: Boolean, eventDispatch: EventDispatcher, invokeMethod: MethodRequest, logger: KLogger): Any? { // there is a STRANGE problem, where if we DO NOT respond/reply to method invocation, and immediate invoke multiple methods -- // the "server" side can have out-of-order method invocation. There are 2 ways to solve this // 1) make the "server" side single threaded