You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/01/22 17:44:54 UTC

[incubator-nlpcraft] branch NLPCRAFT-111 updated: Code review & refactoring.

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-111
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-111 by this push:
     new 87e4f37  Code review & refactoring.
87e4f37 is described below

commit 87e4f37d9c917e3a541923d106c04eae87f79e09
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Jan 22 09:44:40 2021 -0800

    Code review & refactoring.
---
 .../common/extcfg/NCExternalConfigManager.scala    |  4 +-
 .../apache/nlpcraft/common/module/NCModule.scala   | 15 ++++++-
 ...PoolContext.scala => NCThreadPoolContext.scala} | 17 +++++--
 ...PoolManager.scala => NCThreadPoolManager.scala} | 33 +++++++-------
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    |  4 +-
 .../org/apache/nlpcraft/server/NCServer.scala      |  4 +-
 .../server/nlp/core/NCNlpServerManager.scala       |  4 +-
 .../nlp/core/opennlp/NCOpenNlpNerEnricher.scala    |  4 +-
 .../server/nlp/core/opennlp/NCOpenNlpParser.scala  |  4 +-
 .../nlp/enrichers/NCServerEnrichmentManager.scala  |  4 +-
 .../server/nlp/enrichers/date/NCDateEnricher.scala |  4 +-
 .../nlpcraft/server/probe/NCProbeManager.scala     |  4 +-
 .../nlpcraft/server/query/NCQueryManager.scala     |  4 +-
 .../nlpcraft/server/rest/NCBasicRestApi.scala      | 52 +++++++++++-----------
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  4 +-
 15 files changed, 93 insertions(+), 68 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
index 0216941..4dd3225 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.common.config.NCConfigurable
 import org.apache.nlpcraft.common.extcfg.NCExternalConfigType._
 import org.apache.nlpcraft.common.module.NCModule
 import org.apache.nlpcraft.common.module.NCModule.{NCModule, PROBE, SERVER}
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCE, NCService, U}
 import resource.managed
 
@@ -38,7 +38,7 @@ import scala.io.Source
 /**
   * External configuration manager.
   */
-object NCExternalConfigManager extends NCService with NCPoolContext {
+object NCExternalConfigManager extends NCService with NCThreadPoolContext {
     private final val DFLT_DIR = ".nlpcraft/extcfg"
     private final val MD5_FILE = "md5.txt"
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/module/NCModule.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/module/NCModule.scala
index 73531f6..70dcec9 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/module/NCModule.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/module/NCModule.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.common.module
 import org.apache.nlpcraft.common.NCE
 
 /**
- *
+ * Runtime module (server, probe, cli, etc.).
  */
 object NCModule extends Enumeration {
     type NCModule = Value
@@ -29,7 +29,18 @@ object NCModule extends Enumeration {
 
     val SERVER, PROBE, CLI: Value = Value
 
-    def getModule: NCModule = active.getOrElse(throw new NCE(s"Module is not set"))
+    /**
+     * Gets current runtime module.
+     *
+     * @return
+     */
+    def getModule: NCModule = active.getOrElse(throw new NCE(s"Runtime module is not set."))
+
+    /**
+     * Sets current runtime module.
+     *
+     * @param active
+     */
     def setModule(active: NCModule): Unit = this.active = Some(active)
 }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolContext.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
similarity index 77%
rename from nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolContext.scala
rename to nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
index debd2d8..9de16f3 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolContext.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
@@ -21,9 +21,20 @@ import org.apache.nlpcraft.common.U
 import scala.concurrent.ExecutionContext
 
 /**
- * Pool context trait.
+ * Thread pool context trait.
  */
-trait NCPoolContext {
+trait NCThreadPoolContext {
+    /**
+     * Gets name of the thread pool.
+     *
+     * @return
+     */
     def getName: String = U.cleanClassName(getClass, simpleName = false)
-    implicit def getContext: ExecutionContext = NCPoolManager.getContext(getName)
+
+    /**
+     * Implicit execution context.
+     *
+     * @return
+     */
+    implicit def getContext: ExecutionContext = NCThreadPoolManager.getContext(getName)
 }
\ No newline at end of file
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
similarity index 80%
rename from nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
rename to nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
index 7c9cbf1..37cc9b6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
@@ -29,14 +29,13 @@ import scala.collection.JavaConverters._
 import scala.concurrent.ExecutionContext
 
 /**
- * Common pool manager.
+ * Common thread pool manager.
  */
-object NCPoolManager extends NCService {
+object NCThreadPoolManager extends NCService {
     @volatile private var data: ConcurrentHashMap[String, Holder] = new ConcurrentHashMap
 
     private case class Holder(context: ExecutionContext, pool: Option[ExecutorService])
-    // Names same as parameter names of
-    // java.util.concurrent.ThreadPoolExecutor.ThreadPoolExecutor(int, int, long, TimeUnit, BlockingQueue<Runnable>)
+    // Names are same as parameter names of 'ThreadPoolExecutor'.
     private case class PoolCfg(corePoolSize: Int, maximumPoolSize: Int, keepAliveTime: Long)
 
     private object Config extends NCConfigurable {
@@ -51,7 +50,7 @@ object NCPoolManager extends NCService {
                         case SERVER ⇒ "nlpcraft.server.pools"
                         case PROBE ⇒ "nlpcraft.probe.pools"
 
-                        case m ⇒ throw new AssertionError(s"Unexpected module: $m")
+                        case m ⇒ throw new AssertionError(s"Unexpected runtime module: $m")
                     }
                 )
 
@@ -60,9 +59,9 @@ object NCPoolManager extends NCService {
 
                 def get(prop: String): Number = {
                     try
-                        cfgMap.getOrElse(prop, throw new NCE(s"Missed property value '$prop' for pool '$name'"))
+                        cfgMap.getOrElse(prop, throw new NCE(s"Missing property value '$prop' for thread pool: $name"))
                     catch {
-                        case e: ClassCastException ⇒ throw new NCE(s"Invaid property value '$prop' for pool '$name'", e)
+                        case e: ClassCastException ⇒ throw new NCE(s"Invalid property value '$prop' for thread pool: $name", e)
                     }
                 }
 
@@ -90,17 +89,21 @@ object NCPoolManager extends NCService {
                             new LinkedBlockingQueue[Runnable]
                         )
 
-                        logger.info(
-                            s"Executor service created for '$name', module: '${Config.moduleName}'" +
-                            s" with following parameters" +
-                            s": corePoolSize=${pCfg.corePoolSize}" +
-                            s", maximumPoolSize=${pCfg.maximumPoolSize}" +
-                            s", keepAliveTime=${pCfg.keepAliveTime}"
-                        )
+                        logger.info(s"Custom executor service created [ " +
+                            s"name=$name, " +
+                            s"module=${Config.moduleName}, " +
+                            s"corePoolSize=${pCfg.corePoolSize}, " +
+                            s"maximumPoolSize=${pCfg.maximumPoolSize}, " +
+                            s"keepAliveTime=${pCfg.keepAliveTime}" +
+                        "]")
 
                         Holder(ExecutionContext.fromExecutor(p), Some(p))
+
                     case None ⇒
-                        logger.info(s"System executor service used for '$name', module: '${Config.moduleName}'")
+                        logger.info(s"Default system executor service used [ " +
+                            s"name=$name, " +
+                            s"module=${Config.moduleName}" +
+                        "]")
 
                         Holder(ExecutionContext.Implicits.global, None)
                 }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
index eaa3695..db46920 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -29,7 +29,7 @@ import org.apache.nlpcraft.common.nlp.core.NCNlpCoreManager
 import org.apache.nlpcraft.common.nlp.dict.NCDictionaryManager
 import org.apache.nlpcraft.common.nlp.numeric.NCNumericManager
 import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
-import org.apache.nlpcraft.common.pool.NCPoolManager
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
 import org.apache.nlpcraft.common.version.NCVersion
 import org.apache.nlpcraft.common.{NCE, NCService, U, _}
 import org.apache.nlpcraft.model.tools.cmdline.NCCliProbeBeacon
@@ -495,7 +495,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
                 "jarFolder" → cfg.jarsFolder
             )
 
-            startedMgrs += NCPoolManager.start(span)
+            startedMgrs += NCThreadPoolManager.start(span)
             startedMgrs += NCExternalConfigManager.start(span)
             startedMgrs += NCNlpCoreManager.start(span)
             startedMgrs += NCNumericManager.start(span)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
index 0cebaae..abfc142 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
@@ -30,7 +30,7 @@ import org.apache.nlpcraft.common.nlp.core.NCNlpCoreManager
 import org.apache.nlpcraft.common.nlp.dict.NCDictionaryManager
 import org.apache.nlpcraft.common.nlp.numeric.NCNumericManager
 import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
-import org.apache.nlpcraft.common.pool.NCPoolManager
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
 import org.apache.nlpcraft.common.version._
 import org.apache.nlpcraft.model.tools.cmdline.NCCliServerBeacon
 import org.apache.nlpcraft.server.company.NCCompanyManager
@@ -94,7 +94,7 @@ object NCServer extends App with NCIgniteInstance with LazyLogging with NCOpenCe
         NCServerLifecycleManager.beforeStart()
 
         startScopedSpan("startManagers", "relVer" → ver.version, "relDate" → ver.date) { span ⇒
-            startedMgrs += NCPoolManager.start(span)
+            startedMgrs += NCThreadPoolManager.start(span)
             startedMgrs += NCExternalConfigManager.start(span)
             startedMgrs += NCWordNetManager.start(span)
             startedMgrs += NCDictionaryManager.start(span)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
index 2cca087..c30e2e4 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.server.nlp.core
 import io.opencensus.trace.Span
 import org.apache.nlpcraft.common.config.NCConfigurable
 import org.apache.nlpcraft.common.nlp.core.NCNlpCoreManager
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, _}
 
 import scala.collection.Seq
@@ -28,7 +28,7 @@ import scala.collection.Seq
 /**
   * Server NLP manager.
   */
-object NCNlpServerManager extends NCService with NCPoolContext {
+object NCNlpServerManager extends NCService with NCThreadPoolContext {
     @volatile private var parser: NCNlpParser = _
     @volatile private var ners: Map[String, NCNlpNerEnricher] = _
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpNerEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpNerEnricher.scala
index 858cd1e..bedc4f4 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpNerEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpNerEnricher.scala
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.common.nlp.core.opennlp.NCOpenNlpTokenizer
 import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote}
 import org.apache.nlpcraft.common.extcfg.NCExternalConfigManager
 import org.apache.nlpcraft.common.extcfg.NCExternalConfigType.OPENNLP
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, U}
 import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
 import org.apache.nlpcraft.server.ignite.NCIgniteInstance
@@ -36,7 +36,7 @@ import scala.util.control.Exception.catching
 /**
   * OpenNLP NER enricher.
   */
-object NCOpenNlpNerEnricher extends NCService with NCNlpNerEnricher with NCIgniteInstance with NCPoolContext {
+object NCOpenNlpNerEnricher extends NCService with NCNlpNerEnricher with NCIgniteInstance with NCThreadPoolContext {
     @volatile private var nerFinders: Map[NameFinderME, String] = _
     @volatile private var cache: IgniteCache[String, Array[String]] = _
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpParser.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpParser.scala
index f4a425e..93814bd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpParser.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/opennlp/NCOpenNlpParser.scala
@@ -25,7 +25,7 @@ import org.apache.nlpcraft.common.extcfg.NCExternalConfigManager
 import org.apache.nlpcraft.common.extcfg.NCExternalConfigType.OPENNLP
 import org.apache.nlpcraft.common.nlp.core.NCNlpCoreManager
 import org.apache.nlpcraft.common.nlp.core.opennlp.NCOpenNlpTokenizer
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, U}
 import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
 import org.apache.nlpcraft.server.ignite.NCIgniteInstance
@@ -37,7 +37,7 @@ import scala.util.control.Exception.catching
 /**
   * OpenNLP parser implementation.
   */
-object NCOpenNlpParser extends NCService with NCNlpParser with NCIgniteInstance with NCPoolContext{
+object NCOpenNlpParser extends NCService with NCNlpParser with NCIgniteInstance with NCThreadPoolContext{
     @volatile private var tagger: POSTagger = _
     @volatile private var lemmatizer: DictionaryLemmatizer = _
     @volatile private var cache: IgniteCache[String, Array[String]] = _
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/NCServerEnrichmentManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/NCServerEnrichmentManager.scala
index 0a6e76a..2e27adc 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/NCServerEnrichmentManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/NCServerEnrichmentManager.scala
@@ -22,7 +22,7 @@ import org.apache.ignite.IgniteCache
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.common.config.NCConfigurable
 import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote, NCNlpSentenceToken}
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, _}
 import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
 import org.apache.nlpcraft.server.ignite.NCIgniteInstance
@@ -42,7 +42,7 @@ import scala.util.control.Exception.catching
 /**
   * Server enrichment pipeline manager.
   */
-object NCServerEnrichmentManager extends NCService with NCIgniteInstance with NCPoolContext {
+object NCServerEnrichmentManager extends NCService with NCIgniteInstance with NCThreadPoolContext {
     private object Config extends NCConfigurable {
         def isBuiltInEnrichers: Boolean = getStringList("nlpcraft.server.tokenProviders").contains("nlpcraft")
     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
index eac0610..325dc69 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.server.nlp.enrichers.date
 import io.opencensus.trace.Span
 import org.apache.nlpcraft.common.config.NCConfigurable
 import org.apache.nlpcraft.common.nlp.{NCNlpSentence ⇒ Sentence, NCNlpSentenceNote ⇒ Note, NCNlpSentenceToken ⇒ Token}
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, _}
 import org.apache.nlpcraft.server.nlp.enrichers.NCServerEnricher
 import org.apache.nlpcraft.server.nlp.enrichers.date.NCDateConstants._
@@ -36,7 +36,7 @@ import scala.collection.mutable.{LinkedHashMap ⇒ LHM}
 /**
   * Date enricher.
   */
-object NCDateEnricher extends NCServerEnricher with NCPoolContext {
+object NCDateEnricher extends NCServerEnricher with NCThreadPoolContext {
     private object Config extends NCConfigurable {
         def style: NCDateFormatType = getObject("nlpcraft.server.datesFormatStyle", NCDateFormatType.withName)
     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index e1902da..38f92ef 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -25,7 +25,7 @@ import org.apache.nlpcraft.common.config.NCConfigurable
 import org.apache.nlpcraft.common.crypto.NCCipher
 import org.apache.nlpcraft.common.nlp.NCNlpSentence
 import org.apache.nlpcraft.common.nlp.core.NCNlpCoreManager
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.socket.NCSocket
 import org.apache.nlpcraft.common.version.NCVersion
 import org.apache.nlpcraft.common.{NCService, _}
@@ -51,7 +51,7 @@ import scala.util.{Failure, Success}
 /**
   * Probe manager.
   */
-object NCProbeManager extends NCService with NCPoolContext {
+object NCProbeManager extends NCService with NCThreadPoolContext {
     private final val GSON = new Gson()
     private final val TYPE_MODEL_INFO_RESP = new TypeToken[util.HashMap[String, AnyRef]]() {}.getType
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
index 104f2bb..892b8de 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
@@ -21,7 +21,7 @@ import io.opencensus.trace.Span
 import org.apache.ignite.IgniteCache
 import org.apache.ignite.events.{CacheEvent, EventType}
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCService, _}
 import org.apache.nlpcraft.server.apicodes.NCApiStatusCode._
 import org.apache.nlpcraft.server.company.NCCompanyManager
@@ -43,7 +43,7 @@ import scala.util.{Failure, Success}
 /**
   * Query state machine.
   */
-object NCQueryManager extends NCService with NCIgniteInstance with NCOpenCensusServerStats with NCPoolContext {
+object NCQueryManager extends NCService with NCIgniteInstance with NCOpenCensusServerStats with NCThreadPoolContext {
     @volatile private var cache: IgniteCache[String/*Server request ID*/, NCQueryStateMdo] = _
     
     // Promises cannot be used in cache.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index d1aa08c..cafc5c2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -30,7 +30,7 @@ import io.opencensus.stats.Measure
 import io.opencensus.trace.{Span, Status}
 import org.apache.commons.validator.routines.UrlValidator
 import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 import org.apache.nlpcraft.common.{NCE, U}
 import org.apache.nlpcraft.server.apicodes.NCApiStatusCode.{API_OK, _}
 import org.apache.nlpcraft.server.company.NCCompanyManager
@@ -50,7 +50,7 @@ import scala.concurrent.Future
 /**
   * REST API default implementation.
   */
-class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace with NCOpenCensusServerStats with NCPoolContext {
+class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace with NCOpenCensusServerStats with NCThreadPoolContext {
     protected final val GSON = new Gson()
     protected final val URL_VALIDATOR = new UrlValidator(Array("http", "https"), UrlValidator.ALLOW_LOCAL_URLS)
 
@@ -1899,30 +1899,30 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
                                 withRequestTimeoutResponse(_ ⇒ timeoutResp) {
                                     path(API / "health") { health$() } // Duplicate for POST.
                                     path(API / "signin") { withMetric(M_SIGNIN_LATENCY_MS, signin$) } ~
-                                        path(API / "signout") { withMetric(M_SIGNOUT_LATENCY_MS, signout$) } ~
-                                        path(API / "cancel") { withMetric(M_CANCEL_LATENCY_MS, cancel$) } ~
-                                        path(API / "check") { withMetric(M_CHECK_LATENCY_MS, check$) } ~
-                                        path(API / "clear"/ "conversation") { withMetric(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
-                                        path(API / "clear"/ "dialog") { withMetric(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
-                                        path(API / "company"/ "add") { withMetric(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
-                                        path(API / "company"/ "get") { withMetric(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
-                                        path(API / "company" / "update") { withMetric(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
-                                        path(API / "company" / "token" / "reset") { withMetric(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
-                                        path(API / "company" / "delete") { withMetric(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
-                                        path(API / "user" / "get") { withMetric(M_USER_GET_LATENCY_MS, user$Get) } ~
-                                        path(API / "user" / "add") { withMetric(M_USER_ADD_LATENCY_MS, user$Add) } ~
-                                        path(API / "user" / "update") { withMetric(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
-                                        path(API / "user" / "delete") { withMetric(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
-                                        path(API / "user" / "admin") { withMetric(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
-                                        path(API / "user" / "passwd" / "reset") { withMetric(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
-                                        path(API / "user" / "all") { withMetric(M_USER_ALL_LATENCY_MS, user$All) } ~
-                                        path(API / "feedback"/ "add") { withMetric(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
-                                        path(API / "feedback"/ "all") { withMetric(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
-                                        path(API / "feedback" / "delete") { withMetric(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
-                                        path(API / "probe" / "all") { withMetric(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
-                                        path(API / "model" / "sugsyn") { withMetric(M_MODEL_SUGSYN_LATENCY_MS, sugsyn$) } ~
-                                        path(API / "ask") { withMetric(M_ASK_LATENCY_MS, ask$) } ~
-                                        path(API / "ask" / "sync") { withMetric(M_ASK_SYNC_LATENCY_MS, ask$Sync) }
+                                    path(API / "signout") { withMetric(M_SIGNOUT_LATENCY_MS, signout$) } ~
+                                    path(API / "cancel") { withMetric(M_CANCEL_LATENCY_MS, cancel$) } ~
+                                    path(API / "check") { withMetric(M_CHECK_LATENCY_MS, check$) } ~
+                                    path(API / "clear"/ "conversation") { withMetric(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
+                                    path(API / "clear"/ "dialog") { withMetric(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
+                                    path(API / "company"/ "add") { withMetric(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
+                                    path(API / "company"/ "get") { withMetric(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
+                                    path(API / "company" / "update") { withMetric(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
+                                    path(API / "company" / "token" / "reset") { withMetric(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
+                                    path(API / "company" / "delete") { withMetric(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
+                                    path(API / "user" / "get") { withMetric(M_USER_GET_LATENCY_MS, user$Get) } ~
+                                    path(API / "user" / "add") { withMetric(M_USER_ADD_LATENCY_MS, user$Add) } ~
+                                    path(API / "user" / "update") { withMetric(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
+                                    path(API / "user" / "delete") { withMetric(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
+                                    path(API / "user" / "admin") { withMetric(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
+                                    path(API / "user" / "passwd" / "reset") { withMetric(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
+                                    path(API / "user" / "all") { withMetric(M_USER_ALL_LATENCY_MS, user$All) } ~
+                                    path(API / "feedback"/ "add") { withMetric(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
+                                    path(API / "feedback"/ "all") { withMetric(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
+                                    path(API / "feedback" / "delete") { withMetric(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
+                                    path(API / "probe" / "all") { withMetric(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
+                                    path(API / "model" / "sugsyn") { withMetric(M_MODEL_SUGSYN_LATENCY_MS, sugsyn$) } ~
+                                    path(API / "ask") { withMetric(M_ASK_LATENCY_MS, ask$) } ~
+                                    path(API / "ask" / "sync") { withMetric(M_ASK_SYNC_LATENCY_MS, ask$Sync) }
                                 }
                             }
                         }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
index d4de258..28cb645 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
@@ -39,12 +39,12 @@ import org.apache.http.client.methods.HttpPost
 import org.apache.http.entity.StringEntity
 import org.apache.http.impl.client.HttpClients
 import org.apache.nlpcraft.common.makro.NCMacroParser
-import org.apache.nlpcraft.common.pool.NCPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolContext
 
 /**
  * Synonym suggestion manager.
  */
-object NCSuggestSynonymManager extends NCService with NCPoolContext {
+object NCSuggestSynonymManager extends NCService with NCThreadPoolContext {
     // For context word server requests.
     private final val MAX_LIMIT: Int = 10000
     private final val BATCH_SIZE = 20