This is an automated email from the ASF dual-hosted git repository.
sergeykamov 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 ede2b5d WIP.
ede2b5d is described below
commit ede2b5d7495c30d23f889bd531884c581fd514d6
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Jan 25 11:46:46 2021 +0300
WIP.
---
nlpcraft/src/main/resources/nlpcraft.conf | 5 +--
.../common/extcfg/NCExternalConfigManager.scala | 6 ++--
.../nlpcraft/common/pool/NCThreadPoolContext.scala | 40 ----------------------
.../nlpcraft/common/pool/NCThreadPoolManager.scala | 25 ++++++--------
.../probe/mgrs/nlp/NCProbeEnrichmentManager.scala | 17 +++++----
.../server/nlp/core/NCNlpServerManager.scala | 7 ++--
.../nlp/core/opennlp/NCOpenNlpNerEnricher.scala | 11 +++---
.../server/nlp/core/opennlp/NCOpenNlpParser.scala | 7 ++--
.../nlp/enrichers/NCServerEnrichmentManager.scala | 6 ++--
.../server/nlp/enrichers/date/NCDateEnricher.scala | 17 +++++----
.../nlpcraft/server/probe/NCProbeManager.scala | 7 ++--
.../nlpcraft/server/query/NCQueryManager.scala | 12 ++++---
.../nlpcraft/server/rest/NCBasicRestApi.scala | 8 +++--
.../nlpcraft/server/rest/NCRestManager.scala | 7 ++--
.../server/sugsyn/NCSuggestSynonymManager.scala | 8 +++--
15 files changed, 85 insertions(+), 98 deletions(-)
diff --git a/nlpcraft/src/main/resources/nlpcraft.conf
b/nlpcraft/src/main/resources/nlpcraft.conf
index 4d85d8e..b0ecf3c 100644
--- a/nlpcraft/src/main/resources/nlpcraft.conf
+++ b/nlpcraft/src/main/resources/nlpcraft.conf
@@ -211,7 +211,8 @@ nlpcraft {
# TODO: some description (pool name - max thread size)
# min 0, keepAliveTime = 1 min
# pools = {
- # "org.apache.nlpcraft.common.extcfg.NCExternalConfigManager" = 10
+ # "probes.communication": 10,
+ # "probe.requests": 10
# }
}
@@ -334,7 +335,7 @@ nlpcraft {
# TODO: some description (pool name - max thread size)
# min 0, keepAliveTime = 1 min
# pools = {
- # "org.apache.nlpcraft.common.extcfg.NCExternalConfigManager" = 10
+ # "model.solver.pool" = 10
# }
}
}
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 4dd3225..940b3b1 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCE, NCService, U}
import resource.managed
@@ -33,14 +33,16 @@ import java.net.URL
import java.nio.file.Files
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._
+import scala.concurrent.ExecutionContext
import scala.io.Source
/**
* External configuration manager.
*/
-object NCExternalConfigManager extends NCService with NCThreadPoolContext {
+object NCExternalConfigManager extends NCService {
private final val DFLT_DIR = ".nlpcraft/extcfg"
private final val MD5_FILE = "md5.txt"
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
case class Holder(typ: NCExternalConfigType, files: Set[String], modules:
Set[NCModule])
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
deleted file mode 100644
index 9de16f3..0000000
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolContext.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft.common.pool
-
-import org.apache.nlpcraft.common.U
-import scala.concurrent.ExecutionContext
-
-/**
- * Thread pool context trait.
- */
-trait NCThreadPoolContext {
- /**
- * Gets name of the thread pool.
- *
- * @return
- */
- def getName: String = U.cleanClassName(getClass, simpleName = false)
-
- /**
- * 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/NCThreadPoolManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
index dee7f6d..0f4989f 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCThreadPoolManager.scala
@@ -33,19 +33,15 @@ import scala.concurrent.ExecutionContext
object NCThreadPoolManager extends NCService {
private final val KEEP_ALIVE_MS = 60000
- @volatile private var data: ConcurrentHashMap[String, Holder] = new
ConcurrentHashMap
+ @volatile private var hs: ConcurrentHashMap[String, Holder] = new
ConcurrentHashMap
private case class Holder(context: ExecutionContext, pool:
Option[ExecutorService])
private object Config extends NCConfigurable {
- private val module: NCModule = NCModule.getModule
-
- val moduleName: String = module.toString.toLowerCase
-
val sizes: Map[String, Integer] = {
val m: Option[Map[String, Integer]] =
getMapOpt(
- module match {
+ NCModule.getModule match {
case SERVER ⇒ "nlpcraft.server.pools"
case PROBE ⇒ "nlpcraft.probe.pools"
@@ -67,8 +63,10 @@ object NCThreadPoolManager extends NCService {
Config.check()
+ def getSystemContext: ExecutionContext = ExecutionContext.Implicits.global
+
def getContext(name: String): ExecutionContext =
- data.computeIfAbsent(
+ hs.computeIfAbsent(
name,
(_: String) ⇒
Config.sizes.get(name) match {
@@ -84,18 +82,17 @@ object NCThreadPoolManager extends NCService {
logger.info(s"Custom executor service created for
'$name' with maxThreadSize: $maxSize.")
Holder(ExecutionContext.fromExecutor(ex), Some(ex))
-
case None ⇒
- logger.info(s"Default system executor service used for
'$name'")
+ logger.info(s"Default executor service created for
'$name', because it is not configured.")
- Holder(ExecutionContext.Implicits.global, None)
+ Holder(getSystemContext, None)
}
).context
override def start(parent: Span): NCService = startScopedSpan("start",
parent) { _ ⇒
ackStarting()
- data = new ConcurrentHashMap
+ hs = new ConcurrentHashMap
ackStarted()
}
@@ -103,9 +100,9 @@ object NCThreadPoolManager extends NCService {
override def stop(parent: Span): Unit = startScopedSpan("stop", parent) {
_ ⇒
ackStopping()
- data.values().asScala.flatMap(_.pool).foreach(U.shutdownPool)
- data.clear()
- data = null
+ hs.values().asScala.flatMap(_.pool).foreach(U.shutdownPool)
+ hs.clear()
+ hs = null
ackStopped()
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index 62291ca..a0824c1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.common.ascii.NCAsciiTable
import org.apache.nlpcraft.common.config.NCConfigurable
import org.apache.nlpcraft.common.debug.NCLogHolder
import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote}
-import org.apache.nlpcraft.common.pool.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.model._
import org.apache.nlpcraft.model.impl.NCTokenLogger
import org.apache.nlpcraft.model.intent.impl.NCIntentSolverInput
@@ -51,16 +51,19 @@ import java.util.function.Predicate
import java.util.{Date, Objects}
import scala.collection.JavaConverters._
import scala.collection.{Seq, _}
+import scala.concurrent.ExecutionContext
/**
* Probe enrichment manager.
*/
-object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats
with NCThreadPoolContext {
- private final val MAX_NESTED_TOKENS = 32
-
+object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
// Embedded probe Java callback function.
private type EMBEDDED_CB = java.util.function.Consumer[NCEmbeddedResult]
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getContext("model.solver.pool")
+
+ private final val MAX_NESTED_TOKENS = 32
+
private final val mux = new Object()
@volatile private var embeddedCbs: mutable.Set[EMBEDDED_CB] = _
@@ -73,10 +76,12 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats wi
def check(): Unit =
if (resultMaxSize <= 0)
- throw new NCE(s"Configuration property value must be > 0 [" +
+ throw new NCE(
+ s"Configuration property value must be > 0 [" +
s"name=$pre.resultMaxSizeBytes, " +
s"value=$resultMaxSize" +
- s"]")
+ s"]"
+ )
}
Config.check()
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 c30e2e4..8a83077 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,15 +20,18 @@ 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, _}
import scala.collection.Seq
+import scala.concurrent.ExecutionContext
/**
* Server NLP manager.
*/
-object NCNlpServerManager extends NCService with NCThreadPoolContext {
+object NCNlpServerManager extends NCService {
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
+
@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 bedc4f4..a78baa3 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
@@ -20,23 +20,26 @@ package org.apache.nlpcraft.server.nlp.core.opennlp
import io.opencensus.trace.Span
import opennlp.tools.namefind.{NameFinderME, TokenNameFinderModel}
import org.apache.ignite.IgniteCache
-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.NCThreadPoolContext
+import org.apache.nlpcraft.common.nlp.core.opennlp.NCOpenNlpTokenizer
+import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote}
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, U}
import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
import org.apache.nlpcraft.server.ignite.NCIgniteInstance
import org.apache.nlpcraft.server.nlp.core.NCNlpNerEnricher
import resource.managed
+import scala.concurrent.ExecutionContext
import scala.util.control.Exception.catching
/**
* OpenNLP NER enricher.
*/
-object NCOpenNlpNerEnricher extends NCService with NCNlpNerEnricher with
NCIgniteInstance with NCThreadPoolContext {
+object NCOpenNlpNerEnricher extends NCService with NCNlpNerEnricher with
NCIgniteInstance {
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
+
@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 93814bd..c080ca3 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,19 +25,22 @@ 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, U}
import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
import org.apache.nlpcraft.server.ignite.NCIgniteInstance
import org.apache.nlpcraft.server.nlp.core.{NCNlpParser, NCNlpWord}
import resource.managed
+import scala.concurrent.ExecutionContext
import scala.util.control.Exception.catching
/**
* OpenNLP parser implementation.
*/
-object NCOpenNlpParser extends NCService with NCNlpParser with
NCIgniteInstance with NCThreadPoolContext{
+object NCOpenNlpParser extends NCService with NCNlpParser with
NCIgniteInstance {
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
+
@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 2e27adc..fc409b5 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, _}
import org.apache.nlpcraft.server.ignite.NCIgniteHelpers._
import org.apache.nlpcraft.server.ignite.NCIgniteInstance
@@ -37,17 +37,19 @@ import
org.apache.nlpcraft.server.nlp.enrichers.stopword.NCStopWordEnricher
import org.apache.nlpcraft.server.nlp.preproc.NCPreProcessManager
import scala.collection.Seq
+import scala.concurrent.ExecutionContext
import scala.util.control.Exception.catching
/**
* Server enrichment pipeline manager.
*/
-object NCServerEnrichmentManager extends NCService with NCIgniteInstance with
NCThreadPoolContext {
+object NCServerEnrichmentManager extends NCService with NCIgniteInstance {
private object Config extends NCConfigurable {
def isBuiltInEnrichers: Boolean =
getStringList("nlpcraft.server.tokenProviders").contains("nlpcraft")
}
private final val CUSTOM_PREFIXES = Set("google:", "opennlp:",
"stanford:", "spacy:")
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
@volatile private var ners: Map[String, NCNlpNerEnricher] = _
@volatile private var supportedProviders: Set[String] = _
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 325dc69..d0e9dc3 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
@@ -19,30 +19,33 @@ 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.nlp.{NCNlpSentence => Sentence,
NCNlpSentenceNote => Note, NCNlpSentenceToken => Token}
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, _}
import org.apache.nlpcraft.server.nlp.enrichers.NCServerEnricher
import org.apache.nlpcraft.server.nlp.enrichers.date.NCDateConstants._
import org.apache.nlpcraft.server.nlp.enrichers.date.NCDateFormatType._
import java.util
-import java.util.{Calendar ⇒ C}
+import java.util.{Calendar => C}
import scala.collection.JavaConverters._
import scala.collection.immutable.Iterable
import scala.collection.mutable
-import scala.collection.mutable.{LinkedHashMap ⇒ LHM}
+import scala.collection.mutable.{LinkedHashMap => LHM}
+import scala.concurrent.ExecutionContext
/**
* Date enricher.
*/
-object NCDateEnricher extends NCServerEnricher with NCThreadPoolContext {
+object NCDateEnricher extends NCServerEnricher {
+ private type LHM_SS = LHM[String, String]
+
private object Config extends NCConfigurable {
def style: NCDateFormatType =
getObject("nlpcraft.server.datesFormatStyle", NCDateFormatType.withName)
}
- private type LHM_SS = LHM[String, String]
-
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
+
// Correctness is not checked (double spaces etc).
private[date] val prepsFrom = mkPrepositions(FROM)
private[date] val prepsTo = mkPrepositions(TO)
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 38f92ef..4714f3d 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.socket.NCSocket
import org.apache.nlpcraft.common.version.NCVersion
import org.apache.nlpcraft.common.{NCService, _}
@@ -45,15 +45,16 @@ import java.util.Collections
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._
import scala.collection.{Map, mutable}
-import scala.concurrent.{Future, Promise}
+import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.{Failure, Success}
/**
* Probe manager.
*/
-object NCProbeManager extends NCService with NCThreadPoolContext {
+object NCProbeManager extends NCService {
private final val GSON = new Gson()
private final val TYPE_MODEL_INFO_RESP = new
TypeToken[util.HashMap[String, AnyRef]]() {}.getType
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getContext("probes.communication")
// Type safe and eager configuration container.
private object Config extends NCConfigurable {
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 892b8de..aff0c4b 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, _}
import org.apache.nlpcraft.server.apicodes.NCApiStatusCode._
import org.apache.nlpcraft.server.company.NCCompanyManager
@@ -36,21 +36,23 @@ import org.apache.nlpcraft.server.tx.NCTxManager
import org.apache.nlpcraft.server.user.NCUserManager
import java.util.concurrent.ConcurrentHashMap
-import scala.concurrent.{Future, Promise}
+import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.control.Exception._
import scala.util.{Failure, Success}
/**
* Query state machine.
*/
-object NCQueryManager extends NCService with NCIgniteInstance with
NCOpenCensusServerStats with NCThreadPoolContext {
+object NCQueryManager extends NCService with NCIgniteInstance with
NCOpenCensusServerStats {
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getContext("probe.requests")
+
+ private final val MAX_WORDS = 100
+
@volatile private var cache: IgniteCache[String/*Server request ID*/,
NCQueryStateMdo] = _
// Promises cannot be used in cache.
@volatile private var asyncAsks: ConcurrentHashMap[String,
Promise[NCQueryStateMdo]] = _
- private final val MAX_WORDS = 100
-
/**
*
* @param parent Optional parent span.
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 cafc5c2..6f6b146 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.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCE, U}
import org.apache.nlpcraft.server.apicodes.NCApiStatusCode.{API_OK, _}
import org.apache.nlpcraft.server.company.NCCompanyManager
@@ -45,15 +45,17 @@ import spray.json.DefaultJsonProtocol._
import spray.json.{JsObject, JsValue, RootJsonFormat}
import scala.collection.JavaConverters._
-import scala.concurrent.Future
+import scala.concurrent.{ExecutionContext, Future}
/**
* REST API default implementation.
*/
-class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace
with NCOpenCensusServerStats with NCThreadPoolContext {
+class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace
with NCOpenCensusServerStats {
protected final val GSON = new Gson()
protected final val URL_VALIDATOR = new UrlValidator(Array("http",
"https"), UrlValidator.ALLOW_LOCAL_URLS)
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getContext("probes.communication")
+
final val API_VER = 1
final val API = "api" / s"v$API_VER"
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
index b665e43..b89b59a 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
@@ -23,18 +23,19 @@ import akka.http.scaladsl.server._
import akka.stream.Materializer
import io.opencensus.trace.Span
import org.apache.nlpcraft.common.config.NCConfigurable
-import org.apache.nlpcraft.common.pool.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.common.{NCService, _}
-import scala.concurrent.Future
+import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
/**
* REST manager.
*/
-object NCRestManager extends NCService with NCThreadPoolContext {
+object NCRestManager extends NCService {
private implicit val SYSTEM: ActorSystem = ActorSystem("server-rest")
private implicit val MATERIALIZER: Materializer =
Materializer.createMaterializer(SYSTEM)
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
@volatile private var bindFut: Future[Http.ServerBinding] = _
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 a0bb32d..aaa1d2c 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
@@ -30,7 +30,7 @@ import org.apache.nlpcraft.common._
import org.apache.nlpcraft.common.config.NCConfigurable
import org.apache.nlpcraft.common.makro.NCMacroParser
import org.apache.nlpcraft.common.nlp.core.NCNlpPorterStemmer
-import org.apache.nlpcraft.common.pool.NCThreadPoolContext
+import org.apache.nlpcraft.common.pool.NCThreadPoolManager
import org.apache.nlpcraft.server.probe.NCProbeManager
import java.util
@@ -38,13 +38,13 @@ import java.util.concurrent._
import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
import scala.collection.JavaConverters._
import scala.collection.{Seq, mutable}
-import scala.concurrent.{Future, Promise}
+import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.{Failure, Success}
/**
* Synonym suggestion manager.
*/
-object NCSuggestSynonymManager extends NCService with NCThreadPoolContext {
+object NCSuggestSynonymManager extends NCService {
// For context word server requests.
private final val MAX_LIMIT: Int = 10000
private final val BATCH_SIZE = 20
@@ -58,6 +58,8 @@ object NCSuggestSynonymManager extends NCService with
NCThreadPoolContext {
private final val TYPE_RESP = new
TypeToken[util.List[util.List[Suggestion]]]() {}.getType
private final val SEPARATORS = Seq('?', ',', '.', '-', '!')
+ private implicit final val ec: ExecutionContext =
NCThreadPoolManager.getSystemContext
+
private object Config extends NCConfigurable {
val urlOpt: Option[String] =
getStringOpt("nlpcraft.server.ctxword.url")
}