Add entity store at controller
This commit is contained in:
parent
81a1afa2b7
commit
a1c3902b92
@ -2,7 +2,6 @@ package ru.mipt.npm.controls.xodus
|
||||
|
||||
import jetbrains.exodus.entitystore.Entity
|
||||
import jetbrains.exodus.entitystore.StoreTransaction
|
||||
import ru.mipt.npm.controls.api.DeviceMessage
|
||||
import ru.mipt.npm.controls.api.PropertyChangedMessage
|
||||
import ru.mipt.npm.magix.api.MagixMessage
|
||||
|
||||
@ -17,7 +16,7 @@ public fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entit
|
||||
return entity
|
||||
}
|
||||
|
||||
public fun MagixMessage<DeviceMessage>.toEntity(transaction: StoreTransaction): Entity {
|
||||
public fun <T> MagixMessage<T>.toEntity(transaction: StoreTransaction): Entity {
|
||||
val entity = transaction.newEntity("MagixMessage")
|
||||
entity.setProperty("format", format)
|
||||
entity.setProperty("origin", origin)
|
||||
|
@ -25,6 +25,9 @@ dependencies {
|
||||
implementation("no.tornado:tornadofx:1.7.20")
|
||||
implementation("space.kscience:plotlykt-server:0.5.0-dev-1")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.3")
|
||||
implementation("org.jetbrains.xodus:xodus-entity-store:1.3.232")
|
||||
implementation("org.jetbrains.xodus:xodus-environment:1.3.232")
|
||||
implementation("org.jetbrains.xodus:xodus-vfs:1.3.232")
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||
|
@ -6,6 +6,9 @@ import javafx.scene.Parent
|
||||
import javafx.scene.control.TextField
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.stage.Stage
|
||||
import jetbrains.exodus.entitystore.PersistentEntityStore
|
||||
import jetbrains.exodus.entitystore.PersistentEntityStoreImpl
|
||||
import jetbrains.exodus.entitystore.PersistentEntityStores
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.mipt.npm.controls.api.DeviceMessage
|
||||
import ru.mipt.npm.controls.client.connectToMagix
|
||||
@ -14,7 +17,6 @@ import ru.mipt.npm.controls.controllers.install
|
||||
import ru.mipt.npm.controls.demo.car.IVirtualCar.Companion.acceleration
|
||||
import ru.mipt.npm.magix.api.MagixEndpoint
|
||||
import ru.mipt.npm.magix.rsocket.rSocketWithTcp
|
||||
import ru.mipt.npm.magix.rsocket.rSocketWithWebSockets
|
||||
import ru.mipt.npm.magix.server.startMagixServer
|
||||
import space.kscience.dataforge.context.*
|
||||
import tornadofx.*
|
||||
@ -24,6 +26,7 @@ class VirtualCarController : Controller(), ContextAware {
|
||||
var virtualCar: VirtualCar? = null
|
||||
var magixVirtualCar: MagixVirtualCar? = null
|
||||
var magixServer: ApplicationEngine? = null
|
||||
var entityStore: PersistentEntityStore? = null
|
||||
|
||||
override val context = Context("demoDevice") {
|
||||
plugin(DeviceManager)
|
||||
@ -37,11 +40,16 @@ class VirtualCarController : Controller(), ContextAware {
|
||||
//starting magix event loop
|
||||
magixServer = startMagixServer(enableRawRSocket = true, enableZmq = true)
|
||||
magixVirtualCar = deviceManager.install("magix-virtual-car", MagixVirtualCar)
|
||||
entityStore = PersistentEntityStores.newInstance("/home/marvel1337/2021/SCADA/.messages")
|
||||
//Launch device client and connect it to the server
|
||||
val deviceEndpoint = MagixEndpoint.rSocketWithTcp("localhost", DeviceMessage.serializer())
|
||||
if (entityStore != null) {
|
||||
deviceManager.connectToMagix(deviceEndpoint, entityStore = entityStore as PersistentEntityStoreImpl)
|
||||
} else {
|
||||
deviceManager.connectToMagix(deviceEndpoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun shutdown() {
|
||||
logger.info { "Shutting down..." }
|
||||
@ -51,6 +59,8 @@ class VirtualCarController : Controller(), ContextAware {
|
||||
logger.info { "Magix virtual car server stopped" }
|
||||
virtualCar?.close()
|
||||
logger.info { "Virtual car server stopped" }
|
||||
entityStore?.close()
|
||||
logger.info { "Entity store closed" }
|
||||
context.close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user