From 051f4193004b6567d253033e71742855a232fff7 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 30 Aug 2020 23:13:38 +0200 Subject: [PATCH] Flipped packed IDs order for creating connection RMI objects. Added better toString() info --- src/dorkbox/network/rmi/RmiManagerConnections.kt | 8 +++++--- src/dorkbox/network/rmi/RmiManagerGlobal.kt | 3 +-- .../rmi/messages/ConnectionObjectCreateRequest.kt | 10 ++++++++-- .../rmi/messages/ConnectionObjectCreateResponse.kt | 8 +++++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/dorkbox/network/rmi/RmiManagerConnections.kt b/src/dorkbox/network/rmi/RmiManagerConnections.kt index b7f6a312..ff5c02cf 100644 --- a/src/dorkbox/network/rmi/RmiManagerConnections.kt +++ b/src/dorkbox/network/rmi/RmiManagerConnections.kt @@ -52,6 +52,8 @@ internal class RmiManagerConnections( * on the connection+client to get a connection-specific remote object (that exists on the server/client) */ fun getRemoteObject(connection: Connection, kryoId: Int, objectId: Int, interfaceClass: Class): Iface { + require(interfaceClass.isInterface) { "iface must be an interface." } + // so we can just instantly create the proxy object (or get the cached one) var proxyObject = getProxyObject(objectId) if (proxyObject == null) { @@ -78,7 +80,7 @@ internal class RmiManagerConnections( val callbackId = rmiGlobalSupport.registerCallback(callback) // There is no rmiID yet, because we haven't created it! - val message = ConnectionObjectCreateRequest(RmiUtils.packShorts(kryoId, callbackId), objectParameters) + val message = ConnectionObjectCreateRequest(RmiUtils.packShorts(callbackId, kryoId), objectParameters) // We use a callback to notify us when the object is ready. We can't "create this on the fly" because we // have to wait for the object to be created + ID to be assigned on the remote system BEFORE we can create the proxy instance here. @@ -92,8 +94,8 @@ internal class RmiManagerConnections( */ suspend fun onConnectionObjectCreateRequest(endPoint: EndPoint, connection: CONNECTION, message: ConnectionObjectCreateRequest) { - val kryoId = RmiUtils.unpackLeft(message.packedIds) - val callbackId = RmiUtils.unpackRight(message.packedIds) + val callbackId = RmiUtils.unpackLeft(message.packedIds) + val kryoId = RmiUtils.unpackRight(message.packedIds) val objectParameters = message.objectParameters // We have to lookup the iface, since the proxy object requires it diff --git a/src/dorkbox/network/rmi/RmiManagerGlobal.kt b/src/dorkbox/network/rmi/RmiManagerGlobal.kt index 05871b06..00bdb903 100644 --- a/src/dorkbox/network/rmi/RmiManagerGlobal.kt +++ b/src/dorkbox/network/rmi/RmiManagerGlobal.kt @@ -62,8 +62,6 @@ internal class RmiManagerGlobal( rmiId: Int, interfaceClass: Class<*>): RemoteObject { - require(interfaceClass.isInterface) { "iface must be an interface." } - // duplicates are fine, as they represent the same object (as specified by the ID) on the remote side. val cachedMethods = serialization.getMethods(kryoId) @@ -167,6 +165,7 @@ internal class RmiManagerGlobal( */ fun getGlobalRemoteObject(connection: Connection, objectId: Int, interfaceClass: Class): Iface { // this immediately returns BECAUSE the object must have already been created on the server (this is why we specify the rmiId)! + require(interfaceClass.isInterface) { "iface must be an interface." } val kryoId = serialization.getKryoIdForRmiClient(interfaceClass) diff --git a/src/dorkbox/network/rmi/messages/ConnectionObjectCreateRequest.kt b/src/dorkbox/network/rmi/messages/ConnectionObjectCreateRequest.kt index 68052293..796f9e06 100644 --- a/src/dorkbox/network/rmi/messages/ConnectionObjectCreateRequest.kt +++ b/src/dorkbox/network/rmi/messages/ConnectionObjectCreateRequest.kt @@ -15,11 +15,13 @@ */ package dorkbox.network.rmi.messages +import dorkbox.network.rmi.RmiUtils + /** * These use packed IDs, because both are REALLY shorts, but the JVM deals better with ints. * - * @param interfaceClassId (LEFT) the Kryo interface class ID to create - * @param callbackId (RIGHT) to know which callback to use when the object is created + * @param callbackId (LEFT) to know which callback to use when the object is created + * @param interfaceClassId (RIGHT) the Kryo interface class ID to create * @param objectParameters the constructor parameters to create the object with */ data class ConnectionObjectCreateRequest(val packedIds: Int, val objectParameters: Array?) : RmiMessage { @@ -37,4 +39,8 @@ data class ConnectionObjectCreateRequest(val packedIds: Int, val objectParameter override fun hashCode(): Int { return packedIds } + + override fun toString(): String { + return "ConnectionObjectCreateRequest(callback:${RmiUtils.unpackLeft(packedIds)} iface:${RmiUtils.unpackRight(packedIds)})" + } } diff --git a/src/dorkbox/network/rmi/messages/ConnectionObjectCreateResponse.kt b/src/dorkbox/network/rmi/messages/ConnectionObjectCreateResponse.kt index 33fe727b..822ee10e 100644 --- a/src/dorkbox/network/rmi/messages/ConnectionObjectCreateResponse.kt +++ b/src/dorkbox/network/rmi/messages/ConnectionObjectCreateResponse.kt @@ -15,6 +15,8 @@ */ package dorkbox.network.rmi.messages +import dorkbox.network.rmi.RmiUtils + /** * These use packed IDs, because both are REALLY shorts, but the JVM deals better with ints. @@ -22,4 +24,8 @@ package dorkbox.network.rmi.messages * @param callbackId (LEFT) to know which callback to use when the object is created * @param rmiId (RIGHT) the Kryo interface class ID to create */ -data class ConnectionObjectCreateResponse(val packedIds: Int) : RmiMessage +data class ConnectionObjectCreateResponse(val packedIds: Int) : RmiMessage { + override fun toString(): String { + return "ConnectionObjectCreateResponse(callbackId:${RmiUtils.unpackLeft(packedIds)} rmiId:${RmiUtils.unpackUnsignedRight(packedIds)})" + } +}