Flipped packed IDs order for creating connection RMI objects. Added better toString() info

This commit is contained in:
nathan 2020-08-30 23:13:38 +02:00
parent f1fec705b9
commit 051f419300
4 changed files with 21 additions and 8 deletions

View File

@ -52,6 +52,8 @@ internal class RmiManagerConnections<CONNECTION: Connection>(
* on the connection+client to get a connection-specific remote object (that exists on the server/client)
*/
fun <Iface> getRemoteObject(connection: Connection, kryoId: Int, objectId: Int, interfaceClass: Class<Iface>): 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<CONNECTION: Connection>(
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<CONNECTION: Connection>(
*/
suspend fun onConnectionObjectCreateRequest(endPoint: EndPoint<CONNECTION>, 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

View File

@ -62,8 +62,6 @@ internal class RmiManagerGlobal<CONNECTION : Connection>(
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<CONNECTION : Connection>(
*/
fun <Iface> getGlobalRemoteObject(connection: Connection, objectId: Int, interfaceClass: Class<Iface>): 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)

View File

@ -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<Any?>?) : 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)})"
}
}

View File

@ -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)})"
}
}