From f1fec705b9dd928ac425472aa1749dd710a4f2e1 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 30 Aug 2020 23:12:07 +0200 Subject: [PATCH] Tweaked how the settingsStore types are registered with kryo --- src/dorkbox/network/connection/EndPoint.kt | 8 +++++--- src/dorkbox/network/storage/PropertyStore.kt | 11 ----------- src/dorkbox/network/storage/SettingsStore.kt | 12 ++++++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/dorkbox/network/connection/EndPoint.kt b/src/dorkbox/network/connection/EndPoint.kt index bc1c8741..ebf0fd41 100644 --- a/src/dorkbox/network/connection/EndPoint.kt +++ b/src/dorkbox/network/connection/EndPoint.kt @@ -237,12 +237,14 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A settingsStore = config.settingsStore settingsStore.init(serialization, config.settingsStorageSystem.build()) + settingsStore.getSerializationTypes().forEach { + serialization.register(it) + } + crypto = CryptoManagement(logger, settingsStore, type, config) // we are done with initial configuration, now finish serialization - runBlocking { - serialization.finishInit(type) - } + serialization.finishInit(type) } internal suspend fun initEndpointState(): Aeron { diff --git a/src/dorkbox/network/storage/PropertyStore.kt b/src/dorkbox/network/storage/PropertyStore.kt index 12a83b09..031edfc5 100644 --- a/src/dorkbox/network/storage/PropertyStore.kt +++ b/src/dorkbox/network/storage/PropertyStore.kt @@ -17,11 +17,9 @@ package dorkbox.network.storage import dorkbox.network.connection.CryptoManagement import dorkbox.network.serialization.Serialization -import dorkbox.util.bytes.ByteArrayWrapper import dorkbox.util.storage.Storage import org.agrona.collections.Int2ObjectHashMap import java.security.SecureRandom -import java.util.* /** * The property store is the DEFAULT type of store for the network stack. @@ -36,15 +34,6 @@ class PropertyStore : SettingsStore() { * @param serializationManager this is the serialization used for saving objects into the storage database */ override fun init(serializationManager: Serialization, storage: Storage) { - // make sure our custom types are registered - // only register if not ALREADY initialized, since we can initialize in the server and in the client. This creates problems if - // running inside the same JVM (we don't permit it) - if (!serializationManager.initialized()) { - serializationManager.register(HashMap::class.java) - serializationManager.register(ByteArrayWrapper::class.java) - serializationManager.register(DB_Server::class.java) - } - this.storage = storage servers = this.storage.get(DB_Server.STORAGE_KEY, Int2ObjectHashMap()) diff --git a/src/dorkbox/network/storage/SettingsStore.kt b/src/dorkbox/network/storage/SettingsStore.kt index d451c50d..d7daede4 100644 --- a/src/dorkbox/network/storage/SettingsStore.kt +++ b/src/dorkbox/network/storage/SettingsStore.kt @@ -16,9 +16,11 @@ package dorkbox.network.storage import dorkbox.network.serialization.Serialization +import dorkbox.util.bytes.ByteArrayWrapper import dorkbox.util.exceptions.SecurityException import dorkbox.util.storage.Storage import org.slf4j.LoggerFactory +import java.util.* /** * This class provides a way for the network stack to use the server's database, instead of a property file (which it uses when stand-alone) @@ -32,6 +34,16 @@ abstract class SettingsStore : AutoCloseable { */ abstract fun init(serializationManager: Serialization, storage: Storage) + fun getSerializationTypes(): List> { + // make sure our custom types are registered + // only register if not ALREADY initialized, since we can initialize in the server and in the client. This creates problems if + // running inside the same JVM + return listOf(HashMap::class.java, + ByteArrayWrapper::class.java, + DB_Server::class.java + ) + } + /** * Simple, property based method for saving the private key of the server */