From f880b2d63746788428af7a51955989ea86921dff Mon Sep 17 00:00:00 2001 From: Atos1337 Date: Sat, 4 Dec 2021 02:15:57 +0300 Subject: [PATCH] Move to xodus-serialization --- controls-xodus/build.gradle.kts | 1 + .../kotlin/ru/mipt/npm/controls/xodus/connections.kt | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/controls-xodus/build.gradle.kts b/controls-xodus/build.gradle.kts index cf06c4c..9421f36 100644 --- a/controls-xodus/build.gradle.kts +++ b/controls-xodus/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { implementation(projects.magix.magixApi) implementation(projects.controlsMagixClient) implementation(projects.magix.magixServer) + implementation(projects.xodusSerialization) implementation("org.jetbrains.xodus:xodus-entity-store:$xodusVersion") implementation("org.jetbrains.xodus:xodus-environment:$xodusVersion") implementation("org.jetbrains.xodus:xodus-vfs:$xodusVersion") diff --git a/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt b/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt index b1cbf09..126d983 100644 --- a/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt +++ b/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt @@ -12,6 +12,7 @@ import ru.mipt.npm.controls.api.PropertyChangedMessage import ru.mipt.npm.controls.controllers.DeviceManager import ru.mipt.npm.controls.controllers.hubMessageFlow import ru.mipt.npm.magix.server.GenericMagixMessage +import ru.mipt.npm.xodus.serialization.json.encodeToEntity import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Factory import space.kscience.dataforge.context.debug @@ -36,15 +37,13 @@ public object EntityStoreFactory : Factory { @OptIn(InternalCoroutinesApi::class) public fun DeviceManager.connectXodus( factory: Factory, - filterCondition: suspend (DeviceMessage) -> Boolean = { it is PropertyChangedMessage } + filterCondition: suspend (DeviceMessage) -> Boolean = { true } ): Job { val entityStore = factory.invoke(meta, context) logger.debug { "Device entity store opened" } return hubMessageFlow(context).filter(filterCondition).onEach { message -> - entityStore.executeInTransaction { - (message as PropertyChangedMessage).toEntity(it) - } + entityStore.encodeToEntity(message, "DeviceMessage") }.launchIn(context).apply { invokeOnCompletion(onCancelling = true) { entityStore.close() @@ -78,10 +77,7 @@ public fun SharedFlow.storeInXodus( flowFilter: suspend (GenericMagixMessage) -> Boolean = { true }, ){ filter(flowFilter).onEach { message -> - entityStore.executeInTransaction { txn -> - val entity = txn.newEntity("MagixMessage") - entity.setProperty("value", message.toString()) - } + entityStore.encodeToEntity(message, "MagixMessage") } }