JAL-3070 slivka service discovery as a background thread - still need to unify Jabaws...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 3 Oct 2019 16:29:53 +0000 (17:29 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 3 Oct 2019 16:29:53 +0000 (17:29 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java

index 0ca7ddc..e66b8d1 100644 (file)
@@ -4450,8 +4450,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 // JMenuItems for slivka-based services
 
                 SlivkaWSDiscoverer slivkaDiscoverer = SlivkaWSDiscoverer.getInstance();
+                if (slivkaDiscoverer.hasServices())
+                {
                 slivkaDiscoverer.attachWSMenuEntry(webService, me);
+                } else {
+                  if (slivkaDiscoverer.isRunning())
+                  {
+                    {
+                      JMenuItem tm = new JMenuItem(
+                              "Still discovering Slivka Services");
+                      tm.setEnabled(false);
+                      webService.add(tm);
+                    }
 
+                  }
+                }
+              
 
                 build_fetchdbmenu(webService);
                 for (JMenu item : wsmenu)
index 15752ba..84e6aed 100644 (file)
@@ -2557,7 +2557,9 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     Thread t3 = null;
     {
-      // TODO: do rest service discovery
+      // start slivka discovery
+      t3 = new Thread(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance());
+      t3.start();
     }
     if (blocking)
     {
index 1531e2d..b1c9ecb 100644 (file)
@@ -3,9 +3,7 @@ package jalview.ws.slivkaws;
 import jalview.gui.AlignFrame;
 import jalview.ws.WSMenuEntryProviderI;
 import jalview.ws.api.ServiceWithParameters;
-import jalview.ws.jws2.MsaWSClient;
 import jalview.ws.jws2.PreferredServiceRegistry;
-import jalview.ws.jws2.SequenceAnnotationWSClient;
 
 import java.beans.PropertyChangeSupport;
 import java.io.IOError;
@@ -45,35 +43,33 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
     return instance;
   }
 
-  private void addMsaServiceClient(JMenu alignmentMenu,
-          SlivkaService service, AlignFrame alignFrame)
+  List<ServiceWithParameters> getServiceInstances()
   {
-    SlivkaMsaServiceInstance instance = new SlivkaMsaServiceInstance(
-            slivkaClient, service);
-    MsaWSClient client = new MsaWSClient();
-    client.attachWSMenuEntry(alignmentMenu, instance, alignFrame);
-    alignmentMenu.addSeparator();
-  }
-
-  private void addDisorderServiceClient(JMenu disorderMenu,
-          SlivkaService service, AlignFrame alignFrame)
-  {
-    SlivkaAnnotationServiceInstance serviceInstance = new SlivkaAnnotationServiceInstance(
-            slivkaClient, service, false);
-
-    SequenceAnnotationWSClient client = new SequenceAnnotationWSClient();
-    client.attachWSMenuEntry(disorderMenu, serviceInstance, alignFrame);
-    disorderMenu.addSeparator();
-  }
+    List<ServiceWithParameters> instances = new ArrayList<>();
+    for (SlivkaService service : services)
+    {
+      for (String classifier : service.classifiers)
+      {
+        if (classifier.contains("Multiple sequence alignment"))
+        {
+          instances
+                  .add(new SlivkaMsaServiceInstance(slivkaClient, service));
+        }
+        else if (classifier.contains("Protein sequence analysis"))
+        {
+          instances.add(new SlivkaAnnotationServiceInstance(slivkaClient,
+                  service, false));
+        }
+        else if (classifier
+                .contains("Sequence alignment analysis (conservation)"))
+        {
+          instances.add(new SlivkaAnnotationServiceInstance(slivkaClient,
+                  service, true));
+        }
 
-  private void addConservationServiceClient(JMenu conservationMenu,
-          SlivkaService service, AlignFrame alignFrame)
-  {
-    SlivkaAnnotationServiceInstance serviceInstance = new SlivkaAnnotationServiceInstance(
-            slivkaClient, service, true);
-    SequenceAnnotationWSClient client = new SequenceAnnotationWSClient();
-    client.attachWSMenuEntry(conservationMenu, serviceInstance, alignFrame);
-    conservationMenu.addSeparator();
+      }
+    }
+    return instances;
   }
 
   private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
@@ -91,47 +87,49 @@ public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
     slivkaMenu.add(disorderMenu);
     JMenu conservationMenu = new JMenu("Conservation");
     slivkaMenu.add(conservationMenu);
+    PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
+            getServiceInstances(),
+              changeSupport, slivkaMenu, alignFrame, null);
+    
+  }
+
+  List<SlivkaService>services=null;
+
+  volatile boolean started = false, finished = false;
+
+  Thread discoverer = null;
+  @Override
+  public void run()
+  {
+    discoverer = Thread.currentThread();
+    started = true;
     try
     {
-      List<ServiceWithParameters> instances = new ArrayList<>();
-      for (SlivkaService service : slivkaClient.getServices())
-      {
-        for (String classifier : service.classifiers)
-        {
-          if (classifier.contains("Multiple sequence alignment"))
-          {
-            instances.add(
-                    new SlivkaMsaServiceInstance(slivkaClient, service));
-            // addMsaServiceClient(alignmentMenu, service, alignFrame);
-          }
-          else if (classifier.contains("Protein sequence analysis"))
-          {
-            instances.add(new SlivkaAnnotationServiceInstance(slivkaClient,
-                    service, false));
-            // addDisorderServiceClient(disorderMenu, service, alignFrame);
-          }
-          else if (classifier
-                  .contains("Sequence alignment analysis (conservation)"))
-          {
-            instances.add(new SlivkaAnnotationServiceInstance(slivkaClient,
-                    service, true));
-            // addConservationServiceClient(conservationMenu, service,
-            // alignFrame);
-          }
-
-        }
-      }
-      PreferredServiceRegistry.getRegistry().populateWSMenuEntry(instances,
-              changeSupport, slivkaMenu, alignFrame, null);
+      services = slivkaClient.getServices();
     } catch (IOException e)
     {
       throw new IOError(e);
     }
+    finished = true;
   }
 
-  @Override
-  public void run()
+  public static List<ServiceWithParameters> getServices()
   {
+    SlivkaWSDiscoverer us = getInstance();
+    if (us.services == null)
+    {
+      us.run();
+    }
+    return us.getServiceInstances();
+  }
 
+  public boolean hasServices()
+  {
+    return finished == true && services != null && services.size() > 0;
+  }
+
+  public boolean isRunning()
+  {
+    return discoverer != null && discoverer.isAlive();
   }
 }