diff --git a/controls-mongo/README.md b/controls-mongo/README.md new file mode 100644 index 0000000..a627574 --- /dev/null +++ b/controls-mongo/README.md @@ -0,0 +1,26 @@ +# Description +This module allows you to store [DeviceMessages](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt) +from certain [DeviceManager](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/DeviceManager.kt) +or [MagixMessages](magix/magix-api/src/commonMain/kotlin/ru/mipt/npm/magix/api/MagixMessage.kt) +from [magix server](/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/server.kt) +in [mongoDB](https://www.mongodb.com/). + +# Usage + +All usage examples can be found in [VirtualCarController](/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCarController.kt). + +## Storage from Device Manager + +Just call storeMessagesInXodus. For more details, you can see comments in [source code](/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt) + +## Storage from Magix Server + +Just pass such lambda as parameter to startMagixServer: +```kotlin +{ flow -> + // some code + storeInMongo(flow) + // some code +} +``` +For more details, you can see comments in [source code](/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt) diff --git a/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt b/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt index a8a7800..e041171 100644 --- a/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt +++ b/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt @@ -39,6 +39,13 @@ public object DefaultMongoClientFactory : Factory { } ?: KMongo.createClient(DEFAULT_MONGO_DATABASE_URL).coroutine } +/** + * Begin to store DeviceMessages from this DeviceManager + * @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default. + * DeviceManager's meta and context will be used for in invoke method. + * @param filterCondition allow you to specify messages which we want to store. Always true by default. + * @return Job which responsible for our storage + */ @OptIn(InternalCoroutinesApi::class) public fun DeviceManager.connectMongo( factory: Factory, @@ -70,6 +77,12 @@ internal fun Flow.storeInMongo( } } +/** Begin to store MagixMessages from certain flow + * @param flow flow of messages which we will store + * @param meta Meta which may have some configuration parameters for our storage and will be used in invoke method of factory + * @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default. + * @param flowFilter allow you to specify messages which we want to store. Always true by default. + */ @OptIn(InternalCoroutinesApi::class) public fun Application.storeInMongo( flow: MutableSharedFlow, diff --git a/controls-xodus/README.md b/controls-xodus/README.md new file mode 100644 index 0000000..dca332c --- /dev/null +++ b/controls-xodus/README.md @@ -0,0 +1,26 @@ +# Description +This module allows you to store [DeviceMessages](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt) +from certain [DeviceManager](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/DeviceManager.kt) +or [MagixMessages](magix/magix-api/src/commonMain/kotlin/ru/mipt/npm/magix/api/MagixMessage.kt) +from [magix server](/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/server.kt) +in [xodus database](https://github.com/JetBrains/xodus). + +# Usage + +All usage examples can be found in [VirtualCarController](/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCarController.kt). + +## Storage from Device Manager + +Just call connectMongo. For more details, you can see comments in [source code](/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt) + +## Storage from Magix Server + +Just pass such lambda as parameter to startMagixServer: +```kotlin +{ flow -> + // some code + storeInXodus(flow) + // some code +} +``` +For more details, you can see comments in [source code](/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt) 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 8c72785..3fe3ce6 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 @@ -36,6 +36,13 @@ internal val defaultPersistentStoreFactory = object : Factory = defaultPersistentStoreFactory, @@ -83,6 +90,12 @@ internal fun Flow.storeInXodus( } } +/** Begin to store MagixMessages from certain flow + * @param flow flow of messages which we will store + * @param meta Meta which may have some configuration parameters for our storage and will be used in invoke method of factory + * @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default. + * @param flowFilter allow you to specify messages which we want to store. Always true by default. + */ @OptIn(InternalCoroutinesApi::class) public fun Application.storeInXodus( flow: MutableSharedFlow,