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 2020/03/17 22:45:05 UTC

[incubator-nlpcraft] 01/01: Fix for NLPCRAFT-19.

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

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

commit 05519e3e8a8b1e404c27205bbaf98ef705f843f1
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Tue Mar 17 15:44:50 2020 -0700

    Fix for NLPCRAFT-19.
---
 .../nlpcraft/probe/mgrs/conn/NCConnectionManager.scala  | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala b/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
index ad69e71..b200b87 100644
--- a/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
+++ b/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
@@ -275,6 +275,8 @@ object NCConnectionManager extends NCService {
     override def start(parent: Span = null): NCService = startScopedSpan("start", parent) { _ ⇒
         require(NCCommandManager.isStarted)
         require(NCModelManager.isStarted)
+        
+        val ctrlLatch = new CountDownLatch(1)
      
         ctrlThread = U.mkThread("probe-ctrl-thread") { t ⇒
             var dnSock: NCSocket = null
@@ -320,7 +322,7 @@ object NCConnectionManager extends NCService {
                     
                     upSock.socket.setSoTimeout(SO_TIMEOUT)
             
-                    val latch = new CountDownLatch(1)
+                    val exitLatch = new CountDownLatch(1)
             
                     /**
                       *
@@ -335,7 +337,7 @@ object NCConnectionManager extends NCService {
                             logger.info(msg)
                         caller.interrupt() // Interrupt current calling thread.
                 
-                        latch.countDown()
+                        exitLatch.countDown()
                     }
             
                     upThread = U.mkThread("probe-uplink") { t ⇒
@@ -389,10 +391,14 @@ object NCConnectionManager extends NCService {
                     upThread.start()
                     dnThread.start()
                     
+                    // Indicate that server connection is established.
+                    ctrlLatch.countDown()
+                    
                     logger.info("REST server connection established.")
                     
-                    while (!t.isInterrupted && latch.getCount > 0) U.ignoreInterrupt {
-                        latch.await()
+                    // Wait until probe connection is closed.
+                    while (!t.isInterrupted && exitLatch.getCount > 0) U.ignoreInterrupt {
+                        exitLatch.await()
                     }
                     
                     closeAll()
@@ -444,6 +450,9 @@ object NCConnectionManager extends NCService {
         }
      
         ctrlThread.start()
+        
+        // Only return when probe successfully connected to the server.
+        ctrlLatch.await()
      
         super.start()
     }