Code cleanup

This commit is contained in:
nathan 2020-08-28 10:21:10 +02:00
parent 080a60f85d
commit 8ae9b9ddbb
7 changed files with 41 additions and 47 deletions

View File

@ -72,7 +72,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
private val previousClosedConnectionActivity: Long = 0 private val previousClosedConnectionActivity: Long = 0
private val rmiConnectionSupport = RmiManagerConnections(logger, rmiGlobalSupport, serialization) private val rmiConnectionSupport = RmiManagerConnections(logger, listenerManager, rmiGlobalSupport, serialization)
init { init {
// have to do some basic validation of our configuration // have to do some basic validation of our configuration
@ -498,7 +498,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveObject(`object`: Any): Int { suspend fun saveObject(`object`: Any): Int {
return rmiConnectionSupport.saveImplObject(`object`) return rmiConnectionSupport.saveImplObject(`object`)
} }
@ -519,7 +519,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveObject(`object`: Any, objectId: Int): Boolean { suspend fun saveObject(`object`: Any, objectId: Int): Boolean {
return rmiConnectionSupport.saveImplObject(`object`, objectId) return rmiConnectionSupport.saveImplObject(`object`, objectId)
} }
@ -543,8 +543,10 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
inline fun <reified Iface> getObject(objectId: Int): Iface { inline fun <reified Iface> getObject(objectId: Int): Iface {
// NOTE: It's not possible to have reified inside a virtual function // NOTE: It's not possible to have reified inside a virtual function
// https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function // https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function
val kryoId = serialization.getKryoIdForRmiClient(Iface::class.java)
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
return rmiConnectionSupport.getRemoteObject(getConnection(), objectId, Iface::class.java) return rmiConnectionSupport.getRemoteObject(getConnection(), kryoId, objectId, Iface::class.java)
} }
/** /**
@ -568,7 +570,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
suspend inline fun <reified Iface> createObject(vararg objectParameters: Any?, noinline callback: suspend (Int, Iface) -> Unit) { suspend inline fun <reified Iface> createObject(vararg objectParameters: Any?, noinline callback: suspend (Int, Iface) -> Unit) {
// NOTE: It's not possible to have reified inside a virtual function // NOTE: It's not possible to have reified inside a virtual function
// https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function // https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function
val kryoId = serialization.getKryoIdForRmi(Iface::class.java) val kryoId = serialization.getKryoIdForRmiClient(Iface::class.java)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
objectParameters as Array<Any?> objectParameters as Array<Any?>
@ -598,10 +600,10 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
suspend inline fun <reified Iface> createObject(noinline callback: suspend (Int, Iface) -> Unit) { suspend inline fun <reified Iface> createObject(noinline callback: suspend (Int, Iface) -> Unit) {
// NOTE: It's not possible to have reified inside a virtual function // NOTE: It's not possible to have reified inside a virtual function
// https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function // https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function
val classId = serialization.getKryoIdForRmi(Iface::class.java) val kryoId = serialization.getKryoIdForRmiClient(Iface::class.java)
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
rmiConnectionSupport.createRemoteObject(getConnection(), classId, null, callback) rmiConnectionSupport.createRemoteObject(getConnection(), kryoId, null, callback)
} }
// //
@ -628,7 +630,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveGlobalObject(`object`: Any): Int { suspend fun saveGlobalObject(`object`: Any): Int {
return rmiGlobalSupport.saveImplObject(`object`) return rmiGlobalSupport.saveImplObject(`object`)
} }
@ -649,7 +651,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveGlobalObject(`object`: Any, objectId: Int): Boolean { suspend fun saveGlobalObject(`object`: Any, objectId: Int): Boolean {
return rmiGlobalSupport.saveImplObject(`object`, objectId) return rmiGlobalSupport.saveImplObject(`object`, objectId)
} }

View File

@ -95,7 +95,7 @@ open class Configuration {
/** /**
* Specify the serialization manager to use. * Specify the serialization manager to use.
*/ */
var serialization: Serialization = Serialization.DEFAULT() var serialization: Serialization = Serialization()
/** /**
* The idle strategy used when polling the Media Driver for new messages. BackOffIdleStrategy is the DEFAULT. * The idle strategy used when polling the Media Driver for new messages. BackOffIdleStrategy is the DEFAULT.

View File

@ -530,8 +530,8 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveGlobalObject(`object`: Any): Int { suspend fun saveGlobalObject(`object`: Any): Int {
return rmiGlobalSupport.saveImplObject(logger, `object`) return rmiGlobalSupport.saveImplObject(`object`)
} }
/** /**
@ -551,7 +551,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveGlobalObject(`object`: Any, objectId: Int): Boolean { suspend fun saveGlobalObject(`object`: Any, objectId: Int): Boolean {
return rmiGlobalSupport.saveImplObject(logger, `object`, objectId) return rmiGlobalSupport.saveImplObject(`object`, objectId)
} }
} }

View File

@ -97,7 +97,10 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
return pingFuture2?.response ?: -1 return pingFuture2?.response ?: -1
} }
private val endPoint = connectionParameters.endPoint /**
* the endpoint associated with this connection
*/
internal val endPoint = connectionParameters.endPoint
private val listenerManager = atomic<ListenerManager<Connection>?>(null) private val listenerManager = atomic<ListenerManager<Connection>?>(null)
val logger = endPoint.logger val logger = endPoint.logger
@ -158,13 +161,6 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
return remoteKeyChanged return remoteKeyChanged
} }
/**
* @return the endpoint associated with this connection
*/
internal fun endPoint(): EndPoint<*> {
return endPoint
}
// /** // /**
// * This is the per-message sequence number. // * This is the per-message sequence number.
// * // *
@ -442,13 +438,8 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveObject(`object`: Any): Int { suspend fun saveObject(`object`: Any): Int {
val rmiId = rmiConnectionSupport.saveImplObject(`object`) return rmiConnectionSupport.saveImplObject(`object`)
if (rmiId == RemoteObjectStorage.INVALID_RMI) {
logger.error("Invalid RMI ID for saving object: $`object`")
}
return rmiId
} }
/** /**
@ -468,13 +459,8 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
* *
* @see RemoteObject * @see RemoteObject
*/ */
fun saveObject(`object`: Any, objectId: Int): Boolean { suspend fun saveObject(`object`: Any, objectId: Int): Boolean {
val success = rmiConnectionSupport.saveImplObject(`object`, objectId) return rmiConnectionSupport.saveImplObject(`object`, objectId)
if (!success) {
logger.error("Unable to save object $`object` with RMI ID $objectId")
}
return success
} }
/** /**
@ -498,7 +484,10 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
// NOTE: It's not possible to have reified inside a virtual function // NOTE: It's not possible to have reified inside a virtual function
// https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function // https://stackoverflow.com/questions/60037849/kotlin-reified-generic-in-virtual-function
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
return rmiConnectionSupport.getRemoteObject(this, objectId, Iface::class.java) val kryoId = endPoint.serialization.getKryoIdForRmiClient(Iface::class.java)
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
return rmiConnectionSupport.getRemoteObject(this, kryoId, objectId, Iface::class.java)
} }
/** /**
@ -544,7 +533,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
*/ */
suspend fun <Iface> createObject(vararg objectParameters: Any?, callback: suspend (Int, Iface) -> Unit) { suspend fun <Iface> createObject(vararg objectParameters: Any?, callback: suspend (Int, Iface) -> Unit) {
val iFaceClass = ClassHelper.getGenericParameterAsClassForSuperClass(Function2::class.java, callback.javaClass, 1) val iFaceClass = ClassHelper.getGenericParameterAsClassForSuperClass(Function2::class.java, callback.javaClass, 1)
val kryoId = endPoint.serialization.getKryoIdForRmi(iFaceClass) val kryoId = endPoint.serialization.getKryoIdForRmiClient(iFaceClass)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
objectParameters as Array<Any?> objectParameters as Array<Any?>
@ -571,8 +560,8 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
*/ */
suspend fun <Iface> createObject(callback: suspend (Int, Iface) -> Unit) { suspend fun <Iface> createObject(callback: suspend (Int, Iface) -> Unit) {
val iFaceClass = ClassHelper.getGenericParameterAsClassForSuperClass(Function2::class.java, callback.javaClass, 1) val iFaceClass = ClassHelper.getGenericParameterAsClassForSuperClass(Function2::class.java, callback.javaClass, 1)
val interfaceClassId = endPoint.serialization.getKryoIdForRmi(iFaceClass) val kryoId = endPoint.serialization.getKryoIdForRmiClient(iFaceClass)
rmiConnectionSupport.createRemoteObject(this, interfaceClassId, null, callback) rmiConnectionSupport.createRemoteObject(this, kryoId, null, callback)
} }
} }

View File

@ -141,7 +141,7 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A
// we only want one instance of these created. These will be called appropriately // we only want one instance of these created. These will be called appropriately
val settingsStore: SettingsStore val settingsStore: SettingsStore
internal val rmiGlobalSupport = RmiManagerGlobal<CONNECTION>(logger, actionDispatch, config.serialization) internal val rmiGlobalSupport = RmiManagerGlobal<CONNECTION>(logger, listenerManager, actionDispatch, config.serialization)
init { init {
logger.error("NETWORK STACK IS ONLY IPV4 AT THE MOMENT. IPV6 is in progress!") logger.error("NETWORK STACK IS ONLY IPV4 AT THE MOMENT. IPV6 is in progress!")
@ -239,7 +239,6 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A
crypto = CryptoManagement(logger, settingsStore, type, config) crypto = CryptoManagement(logger, settingsStore, type, config)
// we are done with initial configuration, now finish serialization // we are done with initial configuration, now finish serialization
runBlocking { runBlocking {
serialization.finishInit(type) serialization.finishInit(type)
@ -336,7 +335,7 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A
* from a "global" context * from a "global" context
*/ */
internal open fun getRmiConnectionSupport() : RmiManagerConnections<CONNECTION> { internal open fun getRmiConnectionSupport() : RmiManagerConnections<CONNECTION> {
return RmiManagerConnections(logger, rmiGlobalSupport, serialization) return RmiManagerConnections(logger, listenerManager, rmiGlobalSupport, serialization)
} }
/** /**

View File

@ -37,7 +37,9 @@ class RmiDelayedInvocationSpamTest : BaseTest() {
@Test @Test
@Throws(SecurityException::class, IOException::class) @Throws(SecurityException::class, IOException::class)
fun rmiNetwork() { fun rmiNetwork() {
rmi() runBlocking {
rmi()
}
} }
@Test @Test
@ -58,7 +60,7 @@ class RmiDelayedInvocationSpamTest : BaseTest() {
* In this test the server has two objects in an object space. The client * In this test the server has two objects in an object space. The client
* uses the first remote object to get the second remote object. * uses the first remote object to get the second remote object.
*/ */
fun rmi(config: (Configuration) -> Unit = {}) { suspend fun rmi(config: (Configuration) -> Unit = {}) {
val server: Server<Connection> val server: Server<Connection>
val async = false val async = false

View File

@ -34,7 +34,9 @@ class RmiDelayedInvocationTest : BaseTest() {
@Test @Test
@Throws(SecurityException::class, IOException::class) @Throws(SecurityException::class, IOException::class)
fun rmiNetwork() { fun rmiNetwork() {
rmi() runBlocking {
rmi()
}
} }
@Test @Test
@ -55,7 +57,7 @@ class RmiDelayedInvocationTest : BaseTest() {
* In this test the server has two objects in an object space. The client * In this test the server has two objects in an object space. The client
* uses the first remote object to get the second remote object. * uses the first remote object to get the second remote object.
*/ */
fun rmi(config: (Configuration) -> Unit = {}) { suspend fun rmi(config: (Configuration) -> Unit = {}) {
run { run {
val configuration = serverConfig() val configuration = serverConfig()
config(configuration) config(configuration)