in nlpcraft/src/main/scala/org/apache/nlpcraft/internal/conversation/NCConversationManager.scala [55:87]
private def clearForTimeout(): Long =
require(Thread.holdsLock(convs))
val now = NCUtils.now()
val delKeys = mutable.HashSet.empty[String]
for ((key, value) <- convs)
if value.tstamp < now - cfg.getConversationTimeout then
value.conv.clear()
delKeys += key
convs --= delKeys
if convs.nonEmpty then convs.values.map(v => v.tstamp + v.conv.timeoutMs).min
else Long.MaxValue
/**
*
*/
def start(): Unit =
gc = NCUtils.mkThread("conv-mgr-gc", cfg.getId) { t =>
while (!t.isInterrupted)
try
convs.synchronized {
val sleepTime = clearForTimeout() - NCUtils.now()
if sleepTime > 0 then
logger.trace(s"${t.getName} waits for $sleepTime ms.")
convs.wait(sleepTime)
}
catch
case _: InterruptedException => // No-op.
case e: Throwable => logger.error(s"Unexpected error for thread: ${t.getName}", e)
}