Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / ws / jws2 / Jws2Discoverer.java
index 7cf6993..d391f8b 100644 (file)
@@ -21,6 +21,8 @@
 package jalview.ws.jws2;
 
 import jalview.bin.Cache;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.gui.AlignFrame;
 import jalview.util.MessageManager;
 import jalview.ws.ServiceChangeListener;
@@ -58,8 +60,20 @@ import compbio.ws.client.Services;
  * @author JimP
  * 
  */
-public class Jws2Discoverer implements WSDiscovererI, Runnable
+public class Jws2Discoverer implements WSDiscovererI, Runnable, ApplicationSingletonI
 {
+
+  /**
+   * Returns the singleton instance of this class.
+   * 
+   * @return
+   */
+  public static Jws2Discoverer getInstance()
+  {
+    return (Jws2Discoverer) ApplicationSingletonProvider
+            .getInstance(Jws2Discoverer.class);
+  }
+
   public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws";
 
   /*
@@ -68,20 +82,14 @@ public class Jws2Discoverer implements WSDiscovererI, Runnable
   private final static String JWS2HOSTURLS = "JWS2HOSTURLS";
 
   /*
-   * Singleton instance
-   */
-  private static Jws2Discoverer discoverer;
-
-  /*
    * Override for testing only
    */
-  private static List<String> testUrls = null;
+  private List<String> testUrls = null;
 
   // preferred url has precedence over others
   private String preferredUrl;
   
   private Set<ServiceChangeListener> serviceListeners = new CopyOnWriteArraySet<>();
-
   private Vector<String> invalidServiceUrls = null;
 
   private Vector<String> urlsWithoutServices = null;
@@ -331,27 +339,28 @@ public class Jws2Discoverer implements WSDiscovererI, Runnable
    */
   public static void main(String[] args)
   {
+    Jws2Discoverer instance = getInstance();
     if (args.length > 0)
     {
-      testUrls = new ArrayList<>();
+      instance.testUrls = new ArrayList<>();
       for (String url : args)
       {
-        testUrls.add(url);
+        instance.testUrls.add(url);
       }
     }
-    var discoverer = getDiscoverer();
+    var discoverer = getInstance();
     discoverer.addServiceChangeListener((_discoverer, _services) -> {
       if (discoverer.services != null)
       {
         System.out.println("Changesupport: There are now "
                 + discoverer.services.size() + " services");
         int i = 1;
-        for (ServiceWithParameters instance : discoverer.services)
+        for (ServiceWithParameters s_instance : discoverer.services)
         {
           System.out.println(
-                  "Service " + i++ + " " + instance.getClass()
-                          + "@" + instance.getHostURL() + ": "
-                          + instance.getActionText());
+                  "Service " + i++ + " " + s_instance.getClass()
+                          + "@" + s_instance.getHostURL() + ": "
+                          + s_instance.getActionText());
         }
 
       }
@@ -370,19 +379,6 @@ public class Jws2Discoverer implements WSDiscovererI, Runnable
     }
   }
 
-  /**
-   * Returns the singleton instance of this class.
-   * 
-   * @return
-   */
-  public static Jws2Discoverer getDiscoverer()
-  {
-    if (discoverer == null)
-    {
-      discoverer = new Jws2Discoverer();
-    }
-    return discoverer;
-  }
 
   @Override
   public boolean hasServices()