rename methods

This commit is contained in:
Alexander Nozik 2022-01-18 18:39:19 +03:00
parent 427ecbf91a
commit 2e7eefeba9
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
5 changed files with 12 additions and 12 deletions

View File

@ -28,7 +28,7 @@ internal class MongoEventStorage(
private val client: CoroutineClient,
private val meta: Meta = Meta.EMPTY,
) : EventStorage {
override suspend fun <T : Any> storeValueInDeviceHub(value: T, serializer: KSerializer<T>) {
override suspend fun <T : Any> storeDeviceMessage(value: T, serializer: KSerializer<T>) {
val collection = client
.getDatabase(
meta[MONGO_DEVICE_MESSAGE_DATABASE_NAME_PROPERTY]?.string
@ -39,7 +39,7 @@ internal class MongoEventStorage(
collection.insertOne(Json.encodeToString(serializer, value))
}
override suspend fun <T : Any> storeValueInMagixServer(value: T, serializer: KSerializer<T>) {
override suspend fun <T : Any> storeMagixMessage(value: T, serializer: KSerializer<T>) {
val collection = client
.getDatabase(meta[MONGO_MAGIX_MESSAGE_DATABASE_NAME_PROPERTY]?.string
?: DEFAULT_MAGIX_MESSAGE_DATABASE_NAME)

View File

@ -6,15 +6,15 @@ import kotlinx.serialization.serializer
import ru.mipt.npm.controls.api.PropertyChangedMessage
public interface EventStorage : Closeable {
public suspend fun <T : Any> storeValueInDeviceHub(value: T, serializer: KSerializer<T>)
public suspend fun <T : Any> storeDeviceMessage(value: T, serializer: KSerializer<T>)
public suspend fun <T : Any> storeValueInMagixServer(value: T, serializer: KSerializer<T>)
public suspend fun <T : Any> storeMagixMessage(value: T, serializer: KSerializer<T>)
public suspend fun getPropertyHistory(sourceDeviceName: String, propertyName: String): List<PropertyChangedMessage>
}
public suspend inline fun <reified T : Any> EventStorage.storeValueInDeviceHub(value: T): Unit =
storeValueInDeviceHub(value, serializer())
public suspend inline fun <reified T : Any> EventStorage.storeDeviceMessage(value: T): Unit =
storeDeviceMessage(value, serializer())
public suspend inline fun <reified T : Any> EventStorage.storeValueInMagixServer(value: T): Unit =
storeValueInMagixServer(value, serializer())
public suspend inline fun <reified T : Any> EventStorage.storeMagixMessage(value: T): Unit =
storeMagixMessage(value, serializer())

View File

@ -33,7 +33,7 @@ public fun DeviceManager.storeMessages(
logger.debug { "Storage client created" }
return hubMessageFlow(context).filter(filterCondition).onEach { message ->
client.storeValueInDeviceHub(message)
client.storeDeviceMessage(message)
}.launchIn(context).apply {
invokeOnCompletion(onCancelling = true) {
client.close()

View File

@ -20,7 +20,7 @@ internal fun Flow<GenericMagixMessage>.store(
flowFilter: suspend (GenericMagixMessage) -> Boolean = { true },
) {
filter(flowFilter).onEach { message ->
client.storeValueInMagixServer(message)
client.storeMagixMessage(message)
}
}

View File

@ -22,11 +22,11 @@ private const val DEVICE_HUB_ENTITY_TYPE = "DeviceMessage"
private const val MAGIX_SERVER_ENTITY_TYPE = "MagixMessage"
public class XodusEventStorage(private val entityStore: PersistentEntityStore) : EventStorage {
override suspend fun <T : Any> storeValueInDeviceHub(value: T, serializer: KSerializer<T>) {
override suspend fun <T : Any> storeDeviceMessage(value: T, serializer: KSerializer<T>) {
entityStore.encodeToEntity(value, DEVICE_HUB_ENTITY_TYPE, serializer)
}
override suspend fun <T : Any> storeValueInMagixServer(value: T, serializer: KSerializer<T>) {
override suspend fun <T : Any> storeMagixMessage(value: T, serializer: KSerializer<T>) {
entityStore.encodeToEntity(value, MAGIX_SERVER_ENTITY_TYPE, serializer)
}