in plugin-dotnet-agent/src/main/kotlin/jetbrains/buildServer/agent/runner/MessagesGuard.kt [46:89]
override fun serviceMessage(message: ServiceMessage) {
try {
message.attributes.get(IndexAttribute)?.toLongOrNull()?.let { index ->
message.attributes.get(SourceAttribute)?.let { source ->
if (source.isNotBlank()) {
val estimatedIndex = _indices[source]?.let { it + 1L } ?: 0L
when {
// Missed message(s)
index > estimatedIndex -> {
val count = index - estimatedIndex
LOG.warn("Missed message(s) found in \"$source\" from position $estimatedIndex by the amount of $count.")
var counter = 0;
for (newMessage in _messagesSource.read(source, estimatedIndex, count)) {
LOG.warn("Restored: $newMessage")
GetNewBuilder().append(newMessage)
counter++;
}
LOG.warn("Restored $counter message(s) for indices in the range: [${estimatedIndex}, ${index - 1}].")
_indices[source] = index
GetNewBuilder().append(message)
}
// Everything is fine
index == estimatedIndex -> {
_indices[source] = index
GetNewBuilder().append(message)
}
// Duplicate message
else -> {
LOG.warn("Duplicate message: $message")
isModified = true
}
}
}
else {
LOG.debug("The source is blank.")
}
}
}
}
catch (_: Exception) { }
}