Merge branch 'feature/JAL-3686_slivka_client_js_update' into alpha/merge_212_JalviewJ...
[jalview.git] / src / jalview / gui / Desktop.java
index 61f342f..a99bab9 100644 (file)
@@ -120,6 +120,7 @@ import jalview.util.Platform;
 import jalview.util.ShortcutKeyMaskExWrapper;
 import jalview.util.UrlConstants;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.WSDiscovererI;
 import jalview.ws.params.ParamManager;
 import jalview.ws.utils.UrlDownloadClient;
 
@@ -2631,7 +2632,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   public void startServiceDiscovery(boolean blocking)
   {
     boolean alive = true;
-    Thread t0 = null, t1 = null, t2 = null;
+    Thread t0 = null, t1 = null, t2 = null, t3 = null;
     // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
     if (true)
     {
@@ -2649,14 +2650,14 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
-      t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
-              .startDiscoverer(changeSupport);
+      t2 = startServiceDiscovery(
+          jalview.ws.jws2.Jws2Discoverer.getDiscoverer(), false);
     }
-    Thread t3 = null;
+    if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
     {
       // start slivka discovery
-      t3 = new Thread(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance());
-      t3.start();
+      t3 = startServiceDiscovery(
+          jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance(), false);
     }
     if (blocking)
     {
@@ -2668,13 +2669,31 @@ public class Desktop extends jalview.jbgui.GDesktop
         } catch (Exception e)
         {
         }
+        // FIXME: Condition should check the discoverer's isRunning rather than
+        // threads
         alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive())
-                || (t3 != null && t3.isAlive())
-                || (t0 != null && t0.isAlive());
+            || (t3 != null && t3.isAlive()) || (t0 != null && t0.isAlive());
       }
     }
   }
 
+  public Thread startServiceDiscovery(WSDiscovererI discoverer,
+      boolean blocking)
+  {
+    Thread thread = discoverer.startDiscoverer(changeSupport);
+    if (blocking)
+    {
+      try
+      {
+        thread.join();
+      } catch (InterruptedException e)
+      {
+        e.printStackTrace();
+      }
+    }
+    return thread;
+  }
+
   /**
    * called to check if the service discovery process completed successfully.
    * 
@@ -2684,8 +2703,9 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
     {
-      final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
-              .getErrorMessages();
+      final WSDiscovererI discoverer = jalview.ws.jws2.Jws2Discoverer
+          .getDiscoverer();
+      final String ermsg = discoverer.getErrorMessages();
       if (ermsg != null)
       {
         if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))