Rename field in MagixMessage in accordance with https://github.com/waltz-controls/rfc/issues/12

This commit is contained in:
Alexander Nozik 2023-07-29 09:47:59 +03:00
parent 870cb7ef40
commit cf70339a9f
10 changed files with 22 additions and 22 deletions

View File

@ -42,7 +42,7 @@ public fun DeviceManager.connectToMagix(
if (responsePayload != null) { if (responsePayload != null) {
endpoint.broadcast( endpoint.broadcast(
format = controlsMagixFormat, format = controlsMagixFormat,
target = request.origin, target = request.sourceEndpoint,
origin = endpointID, origin = endpointID,
payload = responsePayload, payload = responsePayload,
id = generateId(request), id = generateId(request),

View File

@ -44,8 +44,8 @@ private suspend fun MagixEndpoint.collectEcho(scope: CoroutineScope, n: Int) {
MagixMessage( MagixMessage(
format = "test", format = "test",
payload = JsonObject(emptyMap()), payload = JsonObject(emptyMap()),
origin = "test", sourceEndpoint = "test",
target = "loop", targetEndpoint = "loop",
id = it.toString() id = it.toString()
) )
) )
@ -65,7 +65,7 @@ suspend fun main(): Unit = coroutineScope {
//echo each message //echo each message
flow.onEach { message -> flow.onEach { message ->
if (message.parentId == null) { if (message.parentId == null) {
val m = message.copy(origin = "loop", parentId = message.id, id = message.id + ".response") val m = message.copy(sourceEndpoint = "loop", parentId = message.id, id = message.id + ".response")
logger.info(m.toString()) logger.info(m.toString())
send(m) send(m)
} }

View File

@ -97,7 +97,7 @@ fun main() {
val latest = ConcurrentHashMap<String, Duration>() val latest = ConcurrentHashMap<String, Duration>()
monitorEndpoint.subscribe(DeviceManager.magixFormat).onEach { (magixMessage, payload) -> monitorEndpoint.subscribe(DeviceManager.magixFormat).onEach { (magixMessage, payload) ->
latest[magixMessage.origin] = Clock.System.now() - payload.time!! latest[magixMessage.sourceEndpoint] = Clock.System.now() - payload.time!!
}.launchIn(this) }.launchIn(this)
while (isActive) { while (isActive) {

View File

@ -50,8 +50,8 @@ public suspend fun <T> MagixEndpoint.broadcast(
val message = MagixMessage( val message = MagixMessage(
format = format.defaultFormat, format = format.defaultFormat,
payload = magixJson.encodeToJsonElement(format.serializer, payload), payload = magixJson.encodeToJsonElement(format.serializer, payload),
origin = origin, sourceEndpoint = origin,
target = target, targetEndpoint = target,
id = id, id = id,
parentId = parentId, parentId = parentId,
user = user user = user

View File

@ -27,8 +27,8 @@ import kotlinx.serialization.json.JsonElement
public data class MagixMessage( public data class MagixMessage(
val format: String, val format: String,
val payload: JsonElement, val payload: JsonElement,
val origin: String, val sourceEndpoint: String,
val target: String? = null, val targetEndpoint: String? = null,
val id: String? = null, val id: String? = null,
val parentId: String? = null, val parentId: String? = null,
val user: JsonElement? = null, val user: JsonElement? = null,

View File

@ -16,8 +16,8 @@ public data class MagixMessageFilter(
public fun accepts(message: MagixMessage): Boolean = public fun accepts(message: MagixMessage): Boolean =
format?.contains(message.format) ?: true format?.contains(message.format) ?: true
&& origin?.contains(message.origin) ?: true && origin?.contains(message.sourceEndpoint) ?: true
&& target?.contains(message.target) ?: true && target?.contains(message.targetEndpoint) ?: true
public companion object { public companion object {
public val ALL: MagixMessageFilter = MagixMessageFilter() public val ALL: MagixMessageFilter = MagixMessageFilter()

View File

@ -20,8 +20,8 @@ public fun <T, R> CoroutineScope.launchMagixConverter(
val transformed: MagixMessage = MagixMessage( val transformed: MagixMessage = MagixMessage(
outputFormat, outputFormat,
newPayload, newPayload,
newOrigin ?: message.origin, newOrigin ?: message.sourceEndpoint,
message.target, message.targetEndpoint,
message.id, message.id,
message.parentId, message.parentId,
message.user message.user

View File

@ -80,7 +80,7 @@ public class MqttMagixEndpoint(
//TODO add target name escaping //TODO add target name escaping
internal val defaultBroadcastTopicBuilder: (MagixMessage) -> String = { message -> internal val defaultBroadcastTopicBuilder: (MagixMessage) -> String = { message ->
message.target?.let { "$DEFAULT_MAGIX_TOPIC_NAME/it" } ?: DEFAULT_MAGIX_TOPIC_NAME message.targetEndpoint?.let { "$DEFAULT_MAGIX_TOPIC_NAME/it" } ?: DEFAULT_MAGIX_TOPIC_NAME
} }
internal val defaultSubscribeTopicBuilder: (MagixMessageFilter) -> String = { filter -> internal val defaultSubscribeTopicBuilder: (MagixMessageFilter) -> String = { filter ->

View File

@ -30,13 +30,13 @@ public class XodusMagixStorage(
internal val subscriptionJob = endpoint.subscribe(filter).onEach { message -> internal val subscriptionJob = endpoint.subscribe(filter).onEach { message ->
store.executeInTransaction { transaction -> store.executeInTransaction { transaction ->
transaction.newEntity(MAGIC_MESSAGE_ENTITY_TYPE).apply { transaction.newEntity(MAGIC_MESSAGE_ENTITY_TYPE).apply {
setProperty(MagixMessage::origin.name, message.origin) setProperty(MagixMessage::sourceEndpoint.name, message.sourceEndpoint)
setProperty(MagixMessage::format.name, message.format) setProperty(MagixMessage::format.name, message.format)
setBlobString(MagixMessage::payload.name, MagixEndpoint.magixJson.encodeToString(message.payload)) setBlobString(MagixMessage::payload.name, MagixEndpoint.magixJson.encodeToString(message.payload))
message.target?.let { message.targetEndpoint?.let {
setProperty(MagixMessage::target.name, it) setProperty(MagixMessage::targetEndpoint.name, it)
} }
message.id?.let { message.id?.let {
setProperty(MagixMessage::id.name, it) setProperty(MagixMessage::id.name, it)
@ -63,8 +63,8 @@ public class XodusMagixStorage(
payload = getBlobString(MagixMessage::payload.name)?.let { payload = getBlobString(MagixMessage::payload.name)?.let {
magixJson.parseToJsonElement(it) magixJson.parseToJsonElement(it)
} ?: JsonObject(emptyMap()), } ?: JsonObject(emptyMap()),
origin = getProperty(MagixMessage::origin.name).toString(), sourceEndpoint = getProperty(MagixMessage::sourceEndpoint.name).toString(),
target = getProperty(MagixMessage::target.name)?.toString(), targetEndpoint = getProperty(MagixMessage::targetEndpoint.name)?.toString(),
id = getProperty(MagixMessage::id.name)?.toString(), id = getProperty(MagixMessage::id.name)?.toString(),
parentId = getProperty(MagixMessage::parentId.name)?.toString(), parentId = getProperty(MagixMessage::parentId.name)?.toString(),
user = getBlobString(MagixMessage::user.name)?.let { user = getBlobString(MagixMessage::user.name)?.let {
@ -129,10 +129,10 @@ public class XodusMagixStorage(
transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::format.name, mf.format)?.let { transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::format.name, mf.format)?.let {
res = res.intersect(it) res = res.intersect(it)
} }
transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::origin.name, mf.origin)?.let { transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::sourceEndpoint.name, mf.origin)?.let {
res = res.intersect(it) res = res.intersect(it)
} }
transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::target.name, mf.target)?.let { transaction.findAllIn(MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::targetEndpoint.name, mf.target)?.let {
res = res.intersect(it) res = res.intersect(it)
} }

View File

@ -45,7 +45,7 @@ public fun MagixEndpoint.launchHistory(
broadcast( broadcast(
format = MagixHistory.magixFormat, format = MagixHistory.magixFormat,
payload = sendPayload, payload = sendPayload,
target = request.origin, target = request.sourceEndpoint,
id = generateId(request), id = generateId(request),
parentId = request.id, parentId = request.id,
user = user, user = user,