@@ -33,7 +33,7 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
3333 objectState.map?.entries?.forEach { (key, entry) ->
3434 liveMap.data[key] = LiveMapEntry (
3535 isTombstoned = entry.tombstone ? : false ,
36- tombstonedAt = if (entry.tombstone == true ) System .currentTimeMillis() else null ,
36+ tombstonedAt = if (entry.tombstone == true ) entry.serialTimestamp ? : System .currentTimeMillis() else null ,
3737 timeserial = entry.timeserial,
3838 data = entry.data
3939 )
@@ -51,19 +51,19 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
5151 /* *
5252 * @spec RTLM15 - Applies operations to LiveMap
5353 */
54- internal fun applyOperation (operation : ObjectOperation , messageTimeserial : String? ) {
54+ internal fun applyOperation (operation : ObjectOperation , serial : String? , serialTimestamp : Long ? ) {
5555 val update = when (operation.action) {
5656 ObjectOperationAction .MapCreate -> applyMapCreate(operation) // RTLM15d1
5757 ObjectOperationAction .MapSet -> {
5858 if (operation.mapOp != null ) {
59- applyMapSet(operation.mapOp, messageTimeserial ) // RTLM15d2
59+ applyMapSet(operation.mapOp, serial ) // RTLM15d2
6060 } else {
6161 throw objectError(" No payload found for ${operation.action} op for LiveMap objectId=${objectId} " )
6262 }
6363 }
6464 ObjectOperationAction .MapRemove -> {
6565 if (operation.mapOp != null ) {
66- applyMapRemove(operation.mapOp, messageTimeserial ) // RTLM15d3
66+ applyMapRemove(operation.mapOp, serial, serialTimestamp ) // RTLM15d3
6767 } else {
6868 throw objectError(" No payload found for ${operation.action} op for LiveMap objectId=${objectId} " )
6969 }
@@ -132,7 +132,6 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
132132 // RTLM7a2 - Replace existing entry with new one instead of mutating
133133 liveMap.data[mapOp.key] = LiveMapEntry (
134134 isTombstoned = false , // RTLM7a2c
135- tombstonedAt = null ,
136135 timeserial = timeSerial, // RTLM7a2b
137136 data = mapOp.data // RTLM7a2a
138137 )
@@ -154,6 +153,7 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
154153 private fun applyMapRemove (
155154 mapOp : ObjectMapOp , // RTLM8c1
156155 timeSerial : String? , // RTLM8c2
156+ timeStamp : Long? , // RTLM8c3
157157 ): LiveMapUpdate {
158158 val existingEntry = liveMap.data[mapOp.key]
159159
@@ -168,19 +168,28 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
168168 return noOpMapUpdate
169169 }
170170
171+ val tombstonedAt = if (timeStamp != null ) timeStamp else {
172+ Log .w(
173+ tag,
174+ " No timestamp provided for MAP_REMOVE op on key=\" ${mapOp.key} \" ; using current time as tombstone time; " +
175+ " objectId=${objectId} "
176+ )
177+ System .currentTimeMillis()
178+ }
179+
171180 if (existingEntry != null ) {
172181 // RTLM8a2 - Replace existing entry with new one instead of mutating
173182 liveMap.data[mapOp.key] = LiveMapEntry (
174183 isTombstoned = true , // RTLM8a2c
175- tombstonedAt = System .currentTimeMillis() ,
184+ tombstonedAt = tombstonedAt ,
176185 timeserial = timeSerial, // RTLM8a2b
177186 data = null // RTLM8a2a
178187 )
179188 } else {
180189 // RTLM8b, RTLM8b1
181190 liveMap.data[mapOp.key] = LiveMapEntry (
182191 isTombstoned = true , // RTLM8b2
183- tombstonedAt = System .currentTimeMillis() ,
192+ tombstonedAt = tombstonedAt ,
184193 timeserial = timeSerial
185194 )
186195 }
@@ -224,7 +233,7 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang
224233 val opTimeserial = entry.timeserial
225234 val update = if (entry.tombstone == true ) {
226235 // RTLM17a2 - entry in MAP_CREATE op is removed, try to apply MAP_REMOVE op
227- applyMapRemove(ObjectMapOp (key), opTimeserial)
236+ applyMapRemove(ObjectMapOp (key), opTimeserial, entry.serialTimestamp )
228237 } else {
229238 // RTLM17a1 - entry in MAP_CREATE op is not removed, try to set it via MAP_SET op
230239 applyMapSet(ObjectMapOp (key, entry.data), opTimeserial)
0 commit comments