Fixed issues when deleting RMI objects/proxies
This commit is contained in:
parent
babee06372
commit
1b6880bf7d
|
@ -23,7 +23,6 @@ import dorkbox.network.exceptions.RMIException
|
|||
import dorkbox.network.rmi.messages.ConnectionObjectCreateRequest
|
||||
import dorkbox.network.rmi.messages.ConnectionObjectCreateResponse
|
||||
import dorkbox.network.rmi.messages.ConnectionObjectDeleteRequest
|
||||
import dorkbox.network.rmi.messages.ConnectionObjectDeleteResponse
|
||||
import dorkbox.network.serialization.Serialization
|
||||
import org.slf4j.Logger
|
||||
|
||||
|
@ -90,10 +89,9 @@ class RmiManagerConnections<CONNECTION: Connection> internal constructor(
|
|||
// create the client-side proxy object, if possible. This MUST be an object that is saved for the connection
|
||||
val proxyObject = rmi.getProxyObject(false, connection, rmiId, interfaceClass)
|
||||
|
||||
// this should be executed on a NEW coroutine!
|
||||
try {
|
||||
callback(proxyObject, rmiId)
|
||||
} catch (exception: Exception) {
|
||||
} catch (exception: Throwable) {
|
||||
exception.cleanStackTrace()
|
||||
val newException = RMIException(exception)
|
||||
listenerManager.notifyError(connection, newException)
|
||||
|
@ -116,28 +114,6 @@ class RmiManagerConnections<CONNECTION: Connection> internal constructor(
|
|||
// it DOESN'T matter which "side" we are, just delete both (RMI id's must always represent the same object on both sides)
|
||||
connection.rmi.removeProxyObject(rmiId)
|
||||
connection.rmi.removeImplObject<Any?>(rmiId)
|
||||
|
||||
// tell the "other side" to delete the proxy/impl object
|
||||
connection.send(ConnectionObjectDeleteResponse(rmiId))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called on "client" or "server"
|
||||
*/
|
||||
fun onConnectionObjectDeleteResponse(connection: CONNECTION, message: ConnectionObjectDeleteResponse) {
|
||||
val rmiId = message.rmiId
|
||||
|
||||
// we only create the proxy + execute the callback if the RMI id is valid!
|
||||
if (rmiId == RemoteObjectStorage.INVALID_RMI) {
|
||||
val newException = RMIException("Unable to create RMI object, invalid RMI ID")
|
||||
listenerManager.notifyError(connection, newException)
|
||||
return
|
||||
}
|
||||
|
||||
// it DOESN'T matter which "side" we are, just delete both (RMI id's must always represent the same object on both sides)
|
||||
connection.rmi.removeProxyObject(rmiId)
|
||||
connection.rmi.removeImplObject<Any?>(rmiId)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,12 +116,6 @@ internal class RmiManagerGlobal<CONNECTION: Connection>(logger: Logger) : RmiObj
|
|||
*/
|
||||
rmiConnectionSupport.onConnectionObjectDeleteRequest(connection, message)
|
||||
}
|
||||
is ConnectionObjectDeleteResponse -> {
|
||||
/**
|
||||
* called on "client" or "server"
|
||||
*/
|
||||
rmiConnectionSupport.onConnectionObjectDeleteResponse(connection, message)
|
||||
}
|
||||
is MethodRequest -> {
|
||||
/**
|
||||
* Invokes the method on the object and, sends the result back to the connection that made the invocation request.
|
||||
|
|
|
@ -88,6 +88,15 @@ class RmiSupportConnection<CONNECTION: Connection> : RmiObjectCache {
|
|||
return remoteObjectCreationCallbacks.remove(callbackId)!!
|
||||
}
|
||||
|
||||
internal fun getAllCallbacks(): List<Pair<Int, Any.(Int) -> Unit>> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return remoteObjectCreationCallbacks.getAll() as List<Pair<Int, Any.(Int) -> Unit>>
|
||||
}
|
||||
|
||||
internal fun restoreCallbacks(oldProxyCallbacks: List<Pair<Int, Any.(Int) -> Unit>>) {
|
||||
remoteObjectCreationCallbacks.restoreAll(oldProxyCallbacks)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the RMI proxy objects used by this connection. This is used by session management in order to preserve RMI functionality.
|
||||
*/
|
||||
|
@ -251,6 +260,12 @@ class RmiSupportConnection<CONNECTION: Connection> : RmiObjectCache {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
// it DOESN'T matter which "side" we are, just delete both (RMI id's must always represent the same object on both sides)
|
||||
removeProxyObject(rmiObjectId)
|
||||
removeImplObject<Any?>(rmiObjectId)
|
||||
|
||||
|
||||
// ALWAYS send a message because we don't know if we are the "client" or the "server" - and we want ALL sides cleaned up
|
||||
connection.send(ConnectionObjectDeleteRequest(rmiObjectId))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue