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 a83b7cf WIP.
a83b7cf is described below
commit a83b7cff2d83cc5538f0b3516508fb036bdb33ac
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Jan 22 10:59:30 2021 +0300
WIP.
---
nlpcraft/src/main/resources/nlpcraft.conf | 6 +--
.../nlpcraft/common/pool/NCPoolManager.scala | 46 +++++++++++-----------
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/nlpcraft/src/main/resources/nlpcraft.conf
b/nlpcraft/src/main/resources/nlpcraft.conf
index b60ed14..ed042cf 100644
--- a/nlpcraft/src/main/resources/nlpcraft.conf
+++ b/nlpcraft/src/main/resources/nlpcraft.conf
@@ -208,7 +208,7 @@ nlpcraft {
# 'ctxword' server endpoint URL.
ctxword.url="http://localhost:5000"
- # TODO: some description
+ # TODO: some description (keep these names for consistemt with
ThreadPoolExecutor parameters names)
# pools = {
# "org.apache.nlpcraft.server.rest.NCBasicRestApi" = {
# "corePoolSize" = 2
@@ -334,10 +334,10 @@ nlpcraft {
# When exceeded the request will be automatically rejected.
resultMaxSizeBytes = 1048576
- # TODO: some description
+ # TODO: some description (keep these names for consistemt with
ThreadPoolExecutor parameters names)
# pools = {
# "org.apache.nlpcraft.common.extcfg.NCExternalConfigManager" = {
- # "corePoolSize" = 2
+ # "corePoolSize" = 2.2
# "maximumPoolSize" = 4
# "keepAliveTime" = 1000
# }
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
index 838ca9f..7c9cbf1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/pool/NCPoolManager.scala
@@ -29,12 +29,14 @@ import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext
/**
- *
+ * Common pool manager.
*/
object NCPoolManager 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>)
private case class PoolCfg(corePoolSize: Int, maximumPoolSize: Int,
keepAliveTime: Long)
private object Config extends NCConfigurable {
@@ -47,22 +49,24 @@ object NCPoolManager extends NCService {
getMapOpt(
module match {
case SERVER ⇒ "nlpcraft.server.pools"
- case PROBE ⇒ "nlpcraft.server.pools"
+ case PROBE ⇒ "nlpcraft.probe.pools"
+
case m ⇒ throw new AssertionError(s"Unexpected module:
$m")
}
)
- m.getOrElse(Map.empty).map { case (poolName, poolCfg) ⇒
- def get(name: String): Number = {
- val v = poolCfg.get(name)
-
- if (v == null)
- throw new NCE(s"Missed value '$name' for pool
'$poolName'")
+ m.getOrElse(Map.empty).map { case (name, cfg) ⇒
+ val cfgMap = cfg.asScala
- v
+ def get(prop: String): Number = {
+ try
+ cfgMap.getOrElse(prop, throw new NCE(s"Missed property
value '$prop' for pool '$name'"))
+ catch {
+ case e: ClassCastException ⇒ throw new NCE(s"Invaid
property value '$prop' for pool '$name'", e)
+ }
}
- poolName →
+ name →
PoolCfg(
get("corePoolSize").intValue(),
get("maximumPoolSize").intValue(),
@@ -77,26 +81,26 @@ object NCPoolManager extends NCService {
name,
(_: String) ⇒
Config.factories.get(name) match {
- case Some(poolCfg) ⇒
+ case Some(pCfg) ⇒
val p = new ThreadPoolExecutor(
- poolCfg.corePoolSize,
- poolCfg.maximumPoolSize,
- poolCfg.keepAliveTime,
+ pCfg.corePoolSize,
+ pCfg.maximumPoolSize,
+ pCfg.keepAliveTime,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue[Runnable]
)
logger.info(
- s"Executor service created `$name" +
- s", corePoolSize=${poolCfg.corePoolSize}" +
- s", maximumPoolSize=${poolCfg.maximumPoolSize}" +
- s", keepAliveTime=${poolCfg.keepAliveTime}" +
- s", module: ${Config.moduleName}"
+ 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}"
)
Holder(ExecutionContext.fromExecutor(p), Some(p))
case None ⇒
- logger.info(s"System executor service used for
`$name`, module: `${Config.moduleName}.")
+ logger.info(s"System executor service used for
'$name', module: '${Config.moduleName}'")
Holder(ExecutionContext.Implicits.global, None)
}
@@ -114,9 +118,7 @@ object NCPoolManager extends NCService {
ackStopping()
data.values().asScala.flatMap(_.pool).foreach(U.shutdownPool)
-
data.clear()
-
data = null
ackStopped()