JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / ws / jws2 / Jws2Discoverer.java
index bd4d352..516a719 100644 (file)
@@ -21,8 +21,6 @@
 package jalview.ws.jws2;
 
 import jalview.bin.Cache;
-import jalview.bin.ApplicationSingletonProvider;
-import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvSwingUtils;
@@ -62,29 +60,8 @@ import compbio.ws.client.Services;
  * @author JimP
  * 
  */
-public class Jws2Discoverer
-        implements Runnable, WSMenuEntryProviderI, ApplicationSingletonI
+public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
 {
-
-  /**
-   * Returns the singleton instance of this class.
-   * 
-   * @return
-   */
-  public static Jws2Discoverer getInstance()
-  {
-    return (Jws2Discoverer) ApplicationSingletonProvider
-            .getInstance(Jws2Discoverer.class);
-  }
-
-  /**
-   * Private constructor enforces use of singleton via getDiscoverer()
-   */
-  private Jws2Discoverer()
-  {
-    // use getInstance();
-  }
-
   public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws";
 
   /*
@@ -93,6 +70,11 @@ public class Jws2Discoverer
   private final static String JWS2HOSTURLS = "JWS2HOSTURLS";
 
   /*
+   * Singleton instance
+   */
+  private static Jws2Discoverer discoverer;
+
+  /*
    * Override for testing only
    */
   private static List<String> testUrls = null;
@@ -100,7 +82,7 @@ public class Jws2Discoverer
   // preferred url has precedence over others
   private String preferredUrl;
 
-  protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
+  private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
           this);
 
   private Vector<String> invalidServiceUrls = null;
@@ -121,6 +103,13 @@ public class Jws2Discoverer
   protected Vector<Jws2Instance> services;
 
   /**
+   * Private constructor enforces use of singleton via getDiscoverer()
+   */
+  private Jws2Discoverer()
+  {
+  }
+
+  /**
    * change listeners are notified of "services" property changes
    * 
    * @param listener
@@ -201,7 +190,7 @@ public class Jws2Discoverer
     oldthread = Thread.currentThread();
     try
     {
-      getClass().getClassLoader()
+      Class foo = getClass().getClassLoader()
               .loadClass("compbio.ws.client.Jws2Client");
     } catch (ClassNotFoundException e)
     {
@@ -602,19 +591,19 @@ public class Jws2Discoverer
         testUrls.add(url);
       }
     }
-    Thread runner = getInstance()
+    Thread runner = getDiscoverer()
             .startDiscoverer(new PropertyChangeListener()
             {
 
               @Override
               public void propertyChange(PropertyChangeEvent evt)
               {
-                if (getInstance().services != null)
+                if (getDiscoverer().services != null)
                 {
                   System.out.println("Changesupport: There are now "
-                          + getInstance().services.size() + " services");
+                          + getDiscoverer().services.size() + " services");
                   int i = 1;
-                  for (Jws2Instance instance : getInstance().services)
+                  for (Jws2Instance instance : getDiscoverer().services)
                   {
                     System.out.println("Service " + i++ + " "
                             + instance.getClass() + "@" + instance.getHost()
@@ -641,6 +630,20 @@ public class Jws2Discoverer
     }
   }
 
+  /**
+   * Returns the singleton instance of this class.
+   * 
+   * @return
+   */
+  public static Jws2Discoverer getDiscoverer()
+  {
+    if (discoverer == null)
+    {
+      discoverer = new Jws2Discoverer();
+    }
+    return discoverer;
+  }
+
   public boolean hasServices()
   {
     return !running && services != null && services.size() > 0;