From acbcd68384e7aa1530de3bd554aceff9e5fe67d4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 17 Jul 2016 17:34:24 +0200 Subject: [PATCH] Added logging to MessageBuffer. --- .../com/nutomic/ensichat/core/util/MessageBuffer.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/scala/com/nutomic/ensichat/core/util/MessageBuffer.scala b/core/src/main/scala/com/nutomic/ensichat/core/util/MessageBuffer.scala index 6b10cad..6cb5dfa 100644 --- a/core/src/main/scala/com/nutomic/ensichat/core/util/MessageBuffer.scala +++ b/core/src/main/scala/com/nutomic/ensichat/core/util/MessageBuffer.scala @@ -3,6 +3,7 @@ package com.nutomic.ensichat.core.util import java.util.{TimerTask, Timer} import com.nutomic.ensichat.core.{Address, Message} +import com.typesafe.scalalogging.Logger 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) { + private val logger = Logger(this.getClass) + /** * 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) values += 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) private def handleTimeouts(): Unit = { + val sizeBefore = values.size values = values.filter { e => 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") } }