From: Jim Procter Date: Thu, 3 Oct 2019 16:29:53 +0000 (+0100) Subject: JAL-3070 slivka service discovery as a background thread - still need to unify Jabaws... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e9f72a456e6ead6ed3efc3f6b6011d73a80c40f9;p=jalview.git JAL-3070 slivka service discovery as a background thread - still need to unify Jabaws & slivka discoverer patterns --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0ca7ddc..e66b8d1 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 15752ba..84e6aed 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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) { diff --git a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java index 1531e2d..b1c9ecb 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java +++ b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java @@ -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 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 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); + + } + + Listservices=null; + + volatile boolean started = false, finished = false; + + Thread discoverer = null; + @Override + public void run() + { + discoverer = Thread.currentThread(); + started = true; try { - List 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 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(); } }