Added logging to MessageBuffer.

This commit is contained in:
Felix Ableitner 2016-07-17 17:34:24 +02:00
parent 51b1feee4e
commit acbcd68384

View file

@ -3,6 +3,7 @@ package com.nutomic.ensichat.core.util
import java.util.{TimerTask, Timer} import java.util.{TimerTask, Timer}
import com.nutomic.ensichat.core.{Address, Message} import com.nutomic.ensichat.core.{Address, Message}
import com.typesafe.scalalogging.Logger
import org.joda.time.{Seconds, DateTime, Duration} import org.joda.time.{Seconds, DateTime, Duration}
/** /**
@ -10,6 +11,8 @@ import org.joda.time.{Seconds, DateTime, Duration}
*/ */
class MessageBuffer(localAddress: Address, retryMessageSending: (Address) => Unit) { class MessageBuffer(localAddress: Address, retryMessageSending: (Address) => Unit) {
private val logger = Logger(this.getClass)
/** /**
* The maximum number of times we retry to deliver a message. * The maximum number of times we retry to deliver a message.
*/ */
@ -38,6 +41,7 @@ class MessageBuffer(localAddress: Address, retryMessageSending: (Address) => Uni
val newEntry = new BufferEntry(msg, DateTime.now, retryCount) val newEntry = new BufferEntry(msg, DateTime.now, retryCount)
values += newEntry values += newEntry
retryMessage(newEntry) retryMessage(newEntry)
logger.info(s"Added message to buffer, now ${values.size} messages stored")
} }
/** /**
@ -91,9 +95,13 @@ class MessageBuffer(localAddress: Address, retryMessageSending: (Address) => Uni
def getAllMessages: Set[Message] = values.map(_.message) def getAllMessages: Set[Message] = values.map(_.message)
private def handleTimeouts(): Unit = { private def handleTimeouts(): Unit = {
val sizeBefore = values.size
values = values.filter { e => values = values.filter { e =>
e.retryCount < MaxRetryCount && e.message.header.origin != localAddress e.retryCount < MaxRetryCount && e.message.header.origin != localAddress
} }
val difference = values.size - sizeBefore
if (difference > 0)
logger.info(s"Removed $difference message(s), now ${values.size} messages stored")
} }
} }