import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
+import jalview.ws.WSDiscovererI;
import jalview.ws.api.ServiceWithParameters;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
}
// TODO: move into separate menu builder class.
boolean new_sspred = false;
+
if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
{
- Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
+ WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
if (jws2servs != null)
{
if (jws2servs.hasServices())
}
}
}
- build_urlServiceMenu(me.webService);
-
-
- // TODO Mateusz - follow pattern for adding web service
- // JMenuItems for slivka-based services
- SlivkaWSDiscoverer slivkaDiscoverer = SlivkaWSDiscoverer.getInstance();
- if (slivkaDiscoverer.hasServices())
+ if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
{
- slivkaDiscoverer.attachWSMenuEntry(webService, me);
- } else {
- if (slivkaDiscoverer.isRunning())
+ WSDiscovererI discoverer = SlivkaWSDiscoverer
+ .getInstance();
+ if (discoverer != null)
{
+ if (discoverer.hasServices())
+ {
+ discoverer.attachWSMenuEntry(webService, me);
+ }
+ if (discoverer.isRunning())
{
JMenuItem tm = new JMenuItem(
"Still discovering Slivka Services");
tm.setEnabled(false);
webService.add(tm);
}
-
}
}
-
+ build_urlServiceMenu(me.webService);
build_fetchdbmenu(webService);
for (JMenu item : wsmenu)
{
import jalview.util.Platform;
import jalview.util.UrlConstants;
import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.WSDiscovererI;
import jalview.ws.params.ParamManager;
import jalview.ws.utils.UrlDownloadClient;
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)
{
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)
{
} 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.
*
{
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))
package jalview.ws.slivkaws;
+import jalview.bin.Cache;
import jalview.gui.AlignFrame;
-import jalview.ws.WSMenuEntryProviderI;
+import jalview.ws.WSDiscovererI;
import jalview.ws.api.ServiceWithParameters;
import jalview.ws.jws2.PreferredServiceRegistry;
+import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import java.io.IOError;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
-public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI
+public class SlivkaWSDiscoverer implements WSDiscovererI
{
+ private static final String SLIVKA_HOST_URLS = "SLIVKAHOSTURLS";
+
+ private static final String COMPBIO_SLIVKA = "https://www.compbio.dundee.ac.uk/slivka";
+
private static SlivkaWSDiscoverer instance = null;
- private SlivkaClient slivkaClient;
+ private List<ServiceWithParameters> services = List.of();
private SlivkaWSDiscoverer()
{
- try
- {
- slivkaClient = new SlivkaClient("https://www.compbio.dundee.ac.uk/slivka");
- } catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
}
public static SlivkaWSDiscoverer getInstance()
return instance;
}
- /**
- * TODO: tests needed for logic for determining type of each discovered
- * service. Then reimplement this routine !
- *
- * @return (MSA instances, one AAUI type instance, and the remaining all
- * sequence analysis instances taking 1 sequence only)
- */
- List<ServiceWithParameters> getServiceInstances()
+ private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
+ this);
+
+ @Override
+ public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
+ {
+ JMenu slivkaMenu = new JMenu("Slivka");
+ wsmenu.add(slivkaMenu);
+
+ JMenu alignmentMenu = new JMenu("Sequence Alignment");
+ slivkaMenu.add(alignmentMenu);
+ JMenu disorderMenu = new JMenu("Protein sequence analysis");
+ slivkaMenu.add(disorderMenu);
+ JMenu conservationMenu = new JMenu("Conservation");
+ slivkaMenu.add(conservationMenu);
+ PreferredServiceRegistry.getRegistry().populateWSMenuEntry(services,
+ changeSupport, slivkaMenu, alignFrame, null);
+
+ }
+
+ volatile boolean ready = false;
+
+ volatile Thread discovererThread = null;
+
+ private class DiscovererThread extends Thread
{
- List<ServiceWithParameters> instances = new ArrayList<>();
- for (SlivkaService service : services)
+ private Thread oldThread;
+
+ DiscovererThread(Thread oldThread)
+ {
+ super();
+ this.oldThread = oldThread;
+ }
+
+ @Override
+ public void run()
{
- ServiceWithParameters newinstance = null;
- for (String classifier : service.classifiers)
+ if (oldThread != null)
{
- if (classifier.contains("Multiple sequence alignment"))
+ oldThread.interrupt();
+ try
{
- // MSA services always overwrite
- newinstance = new SlivkaMsaServiceInstance(slivkaClient, service);
+ oldThread.join();
+ } catch (InterruptedException e)
+ {
+ return;
+ } finally
+ {
+ oldThread = null;
}
- if (classifier.contains("Protein sequence analysis"))
+ }
+ ready = false;
+ reloadServices();
+ ready = !isInterrupted();
+ }
+ }
+
+ Thread discoverer = null;
+
+ @Override
+ public Thread startDiscoverer(PropertyChangeListener changeListener)
+ {
+ changeSupport.addPropertyChangeListener(changeListener);
+ ready = false;
+ (discovererThread = new DiscovererThread(discovererThread)).start();
+ return discovererThread;
+ }
+
+ private void reloadServices()
+ {
+ Cache.log.info("Reloading Slivka services");
+ changeSupport.firePropertyChange("services", services, List.of());
+ ArrayList<ServiceWithParameters> instances = new ArrayList<>();
+
+ for (String url : getServiceUrls())
+ {
+ Cache.log.info(url);
+ SlivkaClient client;
+ try
+ {
+ client = new SlivkaClient(url);
+ } catch (URISyntaxException e)
+ {
+ e.printStackTrace();
+ continue;
+ }
+ try
+ {
+ for (SlivkaService service : client.getServices())
{
- if (newinstance == null)
+ SlivkaWSInstance newinstance = null;
+ for (String classifier : service.classifiers)
+ {
+ if (classifier.contains("Multiple sequence alignment"))
{
- newinstance = (new SlivkaAnnotationServiceInstance(
- slivkaClient,
-
- service, false));
+ newinstance = new SlivkaMsaServiceInstance(client, service);
}
- }
-
- if (classifier
+ if (classifier.contains("Protein sequence analysis")
+ && newinstance == null)
+ {
+ newinstance = new SlivkaAnnotationServiceInstance(client,
+ service, false);
+ }
+ if (classifier
.contains("Sequence alignment analysis (conservation)"))
- {
- // always overwrite other instances
- newinstance = new SlivkaAnnotationServiceInstance(slivkaClient,
+ {
+ newinstance = new SlivkaAnnotationServiceInstance(client,
service, true);
+ }
+ }
+ if (newinstance != null)
+ {
+ instances.add(newinstance);
+ }
}
- }
- if (newinstance != null)
+ } catch (IOException e)
{
- instances.add(newinstance);
+ continue;
}
}
- return instances;
- }
- private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
- this);
+ services = instances;
+ changeSupport.firePropertyChange("services", List.of(), services);
+
+ Cache.log.info("Slivka services reloading finished");
+ }
@Override
- public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
+ public List<ServiceWithParameters> getServices()
{
- JMenu slivkaMenu = new JMenu("Slivka");
- wsmenu.add(slivkaMenu);
-
- JMenu alignmentMenu = new JMenu("Sequence Alignment");
- slivkaMenu.add(alignmentMenu);
- JMenu disorderMenu = new JMenu("Protein sequence analysis");
- slivkaMenu.add(disorderMenu);
- JMenu conservationMenu = new JMenu("Conservation");
- slivkaMenu.add(conservationMenu);
- PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
- getServiceInstances(),
- changeSupport, slivkaMenu, alignFrame, null);
-
+ return services;
}
- List<SlivkaService>services=null;
+ @Override
+ public boolean hasServices()
+ {
+ return ready == true && services.size() > 0;
+ }
- volatile boolean started = false, finished = false;
+ @Override
+ public boolean isRunning()
+ {
+ return discovererThread == null || discovererThread.isAlive()
+ || discovererThread.getState() == Thread.State.NEW;
+ }
- Thread discoverer = null;
@Override
- public void run()
+ public void setServiceUrls(List<String> wsUrls)
{
- discoverer = Thread.currentThread();
- started = true;
- try
+ if (wsUrls != null && !wsUrls.isEmpty())
{
- services = slivkaClient.getServices();
- } catch (IOException e)
+ Cache.setProperty(SLIVKA_HOST_URLS, String.join(",", wsUrls));
+ }
+ else
{
- throw new IOError(e);
+ Cache.removeProperty(SLIVKA_HOST_URLS);
}
- finished = true;
}
- public static List<ServiceWithParameters> getServices()
+ @Override
+ public List<String> getServiceUrls()
{
- SlivkaWSDiscoverer us = getInstance();
- if (us.services == null)
+ String surls = Cache.getDefault(SLIVKA_HOST_URLS, COMPBIO_SLIVKA);
+ String[] urls = surls.split(",");
+ ArrayList<String> valid = new ArrayList<>(urls.length);
+ for (String url : urls)
{
- us.run();
+ try
+ {
+ new URL(url);
+ valid.add(url);
+ } catch (MalformedURLException e)
+ {
+ Cache.log.warn("Problem whilst trying to make a URL from '"
+ + ((url != null) ? url : "<null>") + "'");
+ Cache.log.warn(
+ "This was probably due to a malformed comma separated list"
+ + " in the " + SLIVKA_HOST_URLS
+ + " entry of $(HOME)/.jalview_properties)");
+ Cache.log.debug("Exception was ", e);
+ }
}
- return us.getServiceInstances();
+ return valid;
}
- public boolean hasServices()
+ @Override
+ public boolean testServiceUrl(URL url)
{
- return finished == true && services != null && services.size() > 0;
+ return getServerStatusFor(url.toString()) == STATUS_OK;
}
- public boolean isRunning()
+ @Override
+ public int getServerStatusFor(String url)
+ {
+ try
+ {
+ List<?> services = new SlivkaClient(url).getServices();
+ return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK;
+ } catch (IOException | URISyntaxException e)
+ {
+ return STATUS_INVALID;
+ }
+ }
+
+ @Override
+ public String getErrorMessages()
{
- return discoverer != null && discoverer.isAlive();
+ // TODO Auto-generated method stub
+ return "";
}
}