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) {
endpoint.broadcast(
format = controlsMagixFormat,
target = request.origin,
target = request.sourceEndpoint,
origin = endpointID,
payload = responsePayload,
id = generateId(request),

View File

@ -44,8 +44,8 @@ private suspend fun MagixEndpoint.collectEcho(scope: CoroutineScope, n: Int) {
MagixMessage(
format = "test",
payload = JsonObject(emptyMap()),
origin = "test",
target = "loop",
sourceEndpoint = "test",
targetEndpoint = "loop",
id = it.toString()
)
)
@ -65,7 +65,7 @@ suspend fun main(): Unit = coroutineScope {
//echo each message
flow.onEach { message ->
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())
send(m)
}

View File

@ -97,7 +97,7 @@ fun main() {
val latest = ConcurrentHashMap<String, Duration>()
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)
while (isActive) {

View File

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

View File

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

View File

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

View File

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

View File

@ -80,7 +80,7 @@ public class MqttMagixEndpoint(
//TODO add target name escaping
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 ->

View File

@ -30,13 +30,13 @@ public class XodusMagixStorage(
internal val subscriptionJob = endpoint.subscribe(filter).onEach { message ->
store.executeInTransaction { transaction ->
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)
setBlobString(MagixMessage::payload.name, MagixEndpoint.magixJson.encodeToString(message.payload))
message.target?.let {
setProperty(MagixMessage::target.name, it)
message.targetEndpoint?.let {
setProperty(MagixMessage::targetEndpoint.name, it)
}
message.id?.let {
setProperty(MagixMessage::id.name, it)
@ -63,8 +63,8 @@ public class XodusMagixStorage(
payload = getBlobString(MagixMessage::payload.name)?.let {
magixJson.parseToJsonElement(it)
} ?: JsonObject(emptyMap()),
origin = getProperty(MagixMessage::origin.name).toString(),
target = getProperty(MagixMessage::target.name)?.toString(),
sourceEndpoint = getProperty(MagixMessage::sourceEndpoint.name).toString(),
targetEndpoint = getProperty(MagixMessage::targetEndpoint.name)?.toString(),
id = getProperty(MagixMessage::id.name)?.toString(),
parentId = getProperty(MagixMessage::parentId.name)?.toString(),
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 {
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)
}
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)
}

View File

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