X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FJws2Discoverer.java;h=bd4d3525dcb2763eaeb749f4bdcad681c6275ac7;hb=a83adb45bdf9554e270921b4baad94defd314b36;hp=5319eab2979525105e2281d0772b40466db34363;hpb=f4766a7bbcfae845fc95923b01fa14ff83d589ff;p=jalview.git diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 5319eab..bd4d352 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -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.gui.Desktop; import jalview.gui.JvSwingUtils; @@ -60,8 +62,29 @@ import compbio.ws.client.Services; * @author JimP * */ -public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI +public class Jws2Discoverer + implements Runnable, WSMenuEntryProviderI, ApplicationSingletonI { + + /** + * 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"; /* @@ -70,11 +93,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI private final static String JWS2HOSTURLS = "JWS2HOSTURLS"; /* - * Singleton instance - */ - private static Jws2Discoverer discoverer; - - /* * Override for testing only */ private static List testUrls = null; @@ -82,7 +100,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI // preferred url has precedence over others private String preferredUrl; - private PropertyChangeSupport changeSupport = new PropertyChangeSupport( + protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); private Vector invalidServiceUrls = null; @@ -103,13 +121,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI protected Vector services; /** - * Private constructor enforces use of singleton via getDiscoverer() - */ - private Jws2Discoverer() - { - } - - /** * change listeners are notified of "services" property changes * * @param listener @@ -178,7 +189,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI running = true; // first set up exclusion list if needed - final Set ignoredServices = new HashSet(); + final Set ignoredServices = new HashSet<>(); for (String ignored : Cache .getDefault("IGNORED_JABAWS_SERVICETYPES", "").split("\\|")) { @@ -190,7 +201,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI oldthread = Thread.currentThread(); try { - Class foo = getClass().getClassLoader() + getClass().getClassLoader() .loadClass("compbio.ws.client.Jws2Client"); } catch (ClassNotFoundException e) { @@ -217,9 +228,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { validServiceUrls.removeAllElements(); } - ArrayList svctypes = new ArrayList(); + ArrayList svctypes = new ArrayList<>(); - List qrys = new ArrayList(); + List qrys = new ArrayList<>(); for (final String jwsserver : getServiceUrls()) { JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsserver); @@ -249,7 +260,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } catch (Exception e) { } - ; for (JabaWsServerQuery squery : qrys) { if (squery.isRunning()) @@ -285,7 +295,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI + svctypes.indexOf(svc.serviceType); } jalview.util.QuickSort.sort(spos, svcs); - services = new Vector(); + services = new Vector<>(); for (Jws2Instance svc : svcs) { if (!ignoredServices.contains(svc.serviceType)) @@ -312,7 +322,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (services == null) { - services = new Vector(); + services = new Vector<>(); } System.out.println( "Discovered service: " + jwsservers + " " + service.toString()); @@ -329,7 +339,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI service.hasParameters(); if (validServiceUrls == null) { - validServiceUrls = new Vector(); + validServiceUrls = new Vector<>(); } validServiceUrls.add(jwsservers); } @@ -363,10 +373,10 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI * for moment we keep them separate. */ JMenu atpoint; - List enumerableServices = new ArrayList(); + List enumerableServices = new ArrayList<>(); // jws2al.removeAll(); - Map preferredHosts = new HashMap(); - Map> alternates = new HashMap>(); + Map preferredHosts = new HashMap<>(); + Map> alternates = new HashMap<>(); for (Jws2Instance service : services.toArray(new Jws2Instance[0])) { if (!isRecalculable(service.action)) @@ -395,7 +405,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (ph == null) { - ph = new ArrayList(); + ph = new ArrayList<>(); } ph.add(service); alternates.put(service.serviceType, ph); @@ -457,7 +467,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI sv.action, sv); changeSupport.firePropertyChange("services", new Vector(), services); - }; + } }).start(); } @@ -483,17 +493,17 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ JMenu atpoint; - List hostLabels = new ArrayList(); - Hashtable lasthostFor = new Hashtable(); - Hashtable> hosts = new Hashtable>(); - ArrayList hostlist = new ArrayList(); + List hostLabels = new ArrayList<>(); + Hashtable lasthostFor = new Hashtable<>(); + Hashtable> hosts = new Hashtable<>(); + ArrayList hostlist = new ArrayList<>(); for (Jws2Instance service : enumerableServices) { ArrayList hostservices = hosts.get(service.getHost()); if (hostservices == null) { hosts.put(service.getHost(), - hostservices = new ArrayList()); + hostservices = new ArrayList<>()); hostlist.add(service.getHost()); } hostservices.add(service); @@ -577,30 +587,34 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } + /** + * + * @param args + * @j2sIgnore + */ public static void main(String[] args) { if (args.length > 0) { - testUrls = new ArrayList(); + testUrls = new ArrayList<>(); for (String url : args) { testUrls.add(url); } - ; } - Thread runner = getDiscoverer() + Thread runner = getInstance() .startDiscoverer(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (getDiscoverer().services != null) + if (getInstance().services != null) { System.out.println("Changesupport: There are now " - + getDiscoverer().services.size() + " services"); + + getInstance().services.size() + " services"); int i = 1; - for (Jws2Instance instance : getDiscoverer().services) + for (Jws2Instance instance : getInstance().services) { System.out.println("Service " + i++ + " " + instance.getClass() + "@" + instance.getHost() @@ -618,7 +632,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } catch (InterruptedException e) { } - ; } try { @@ -628,20 +641,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } - /** - * 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; @@ -685,7 +684,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI // return test urls, if there are any, instead of touching cache return testUrls; } - List urls = new ArrayList(); + List urls = new ArrayList<>(); if (this.preferredUrl != null) { @@ -733,8 +732,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI public Vector getServices() { - return (services == null) ? new Vector() - : new Vector(services); + return (services == null) ? new Vector<>() + : new Vector<>(services); } /** @@ -839,7 +838,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (urlsWithoutServices == null) { - urlsWithoutServices = new Vector(); + urlsWithoutServices = new Vector<>(); } if ((invalidServiceUrls == null @@ -859,7 +858,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (invalidServiceUrls == null) { - invalidServiceUrls = new Vector(); + invalidServiceUrls = new Vector<>(); } if (!invalidServiceUrls.contains(jwsservers)) { @@ -947,7 +946,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ public Jws2Instance getPreferredServiceFor(String[] serviceURLs) { - HashSet urls = new HashSet(); + HashSet urls = new HashSet<>(); urls.addAll(Arrays.asList(serviceURLs)); Jws2Instance match = null; if (services != null) @@ -974,7 +973,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return match; } - Map> preferredServiceMap = new HashMap>();; + Map> preferredServiceMap = new HashMap<>(); /** * get current preferred service of the given type, or global default @@ -1026,12 +1025,12 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); if (preferredServiceMap == null) { - preferredServiceMap = new HashMap>(); + preferredServiceMap = new HashMap<>(); } Map prefmap = preferredServiceMap.get(afid); if (prefmap == null) { - prefmap = new HashMap(); + prefmap = new HashMap<>(); preferredServiceMap.put(afid, prefmap); } prefmap.put(serviceType, selectedServer.getHost());