X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fws%2Fjws2%2FJws2Discoverer.java;h=49f31952553309e7e7676278dee62ca9f4097283;hb=95e91262358d5232185ad1140505f289a270a8cd;hp=d270c8533cbfb314c3b52acdd8872d7b670d94f9;hpb=d95566a60c5dbc13f653c1e52bfa06954f1fbf4d;p=jalview.git diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index d270c85..49f3195 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -364,11 +364,11 @@ 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<>(); - for (Jws2Instance service : services.toArray(new Jws2Instance[0])) + for (ServiceWithParameters service : getServices()) { // TODO: check this behaves with refactored serviceType to getName if (!isRecalculable(service.getName())) @@ -476,7 +476,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ private void addEnumeratedServices(final JMenu jws2al, final AlignFrame alignFrame, - List enumerableServices) + List enumerableServices) { boolean byhost = Cache.getDefault("WSMENU_BYHOST", false), bytype = Cache.getDefault("WSMENU_BYTYPE", false); @@ -488,11 +488,11 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI List hostLabels = new ArrayList<>(); Hashtable lasthostFor = new Hashtable<>(); - Hashtable> hosts = new Hashtable<>(); + Hashtable> hosts = new Hashtable<>(); ArrayList hostlist = new ArrayList<>(); - for (Jws2Instance service : enumerableServices) + for (ServiceWithParameters service : enumerableServices) { - ArrayList hostservices = hosts + ArrayList hostservices = hosts .get(service.getHostURL()); if (hostservices == null) { @@ -582,6 +582,120 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } + /** + * pick the user's preferred service based on a set of URLs (jaba server + * locations) and service URIs (specifying version and service interface + * class) + * + * @param serviceURL + * @return null or best match for given uri/ls. + */ + public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs) + { + HashSet urls = new HashSet<>(); + urls.addAll(Arrays.asList(serviceURLs)); + ServiceWithParameters match = null; + List ourServices = getServices(); + + if (ourServices != null) + { + for (ServiceWithParameters svc : ourServices) + { + // TODO getNameURI Should return a versioned URI for the service, but + // doesn't as of 2.11 + if (urls.contains(svc.getNameURI())) + { + if (match == null) + { + // for moment we always pick service from server ordered first in + // user's preferences + match = svc; + } + if (urls.contains(svc.getUri())) + { + // stop and return - we've matched type URI and URI for service + // endpoint + return svc; + } + } + } + } + return match; + } + + Map> preferredServiceMap = new HashMap<>(); + + /** + * get current preferred endpoint of the given Jabaws service, or global + * default + * + * @param af + * null or a specific alignFrame + * @param serviceName + * Jws2Instance.getName() for service + * @return null if no service of this type is available, the preferred service + * for the serviceType and af if specified and if defined. + */ + public ServiceWithParameters getPreferredServiceFor(AlignFrame af, + String serviceName) + { + String serviceurl = null; + synchronized (preferredServiceMap) + { + String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); + Map prefmap = preferredServiceMap.get(afid); + if (afid.length() > 0 && prefmap == null) + { + // recover global setting, if any + prefmap = preferredServiceMap.get(""); + } + if (prefmap != null) + { + serviceurl = prefmap.get(serviceName); + } + + } + ServiceWithParameters response = null; + for (ServiceWithParameters svc : getServices()) + { + if (svc.getName().equals(serviceName)) + { + if (serviceurl == null || serviceurl.equals(svc.getHostURL())) + { + response = svc; + break; + } + } + } + return response; + } + + public void setPreferredServiceFor(AlignFrame af, String serviceName, + String serviceAction, ServiceWithParameters selectedServer) + { + // TODO: pull out and generalise for the selectedServer's attributes + String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); + if (preferredServiceMap == null) + { + preferredServiceMap = new HashMap<>(); + } + Map prefmap = preferredServiceMap.get(afid); + if (prefmap == null) + { + prefmap = new HashMap<>(); + preferredServiceMap.put(afid, prefmap); + } + prefmap.put(serviceName, selectedServer.getHostURL()); + prefmap.put(serviceAction, selectedServer.getHostURL()); + } + + public void setPreferredServiceFor(String serviceType, + String serviceAction, ServiceWithParameters selectedServer) + { + setPreferredServiceFor(null, serviceType, serviceAction, + selectedServer); + } + public static void main(String[] args) { if (args.length > 0) @@ -944,120 +1058,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } /** - * pick the user's preferred service based on a set of URLs (jaba server - * locations) and service URIs (specifying version and service interface - * class) - * - * @param serviceURL - * @return null or best match for given uri/ls. - */ - public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs) - { - HashSet urls = new HashSet<>(); - urls.addAll(Arrays.asList(serviceURLs)); - ServiceWithParameters match = null; - List ourServices = getServices(); - - if (ourServices != null) - { - for (ServiceWithParameters svc : ourServices) - { - // TODO getNameURI Should return a versioned URI for the service, but - // doesn't as of 2.11 - if (urls.contains(svc.getNameURI())) - { - if (match == null) - { - // for moment we always pick service from server ordered first in - // user's preferences - match = svc; - } - if (urls.contains(svc.getUri())) - { - // stop and return - we've matched type URI and URI for service - // endpoint - return svc; - } - } - } - } - return match; - } - - Map> preferredServiceMap = new HashMap<>(); - - /** - * get current preferred endpoint of the given Jabaws service, or global - * default - * - * @param af - * null or a specific alignFrame - * @param serviceName - * Jws2Instance.getName() for service - * @return null if no service of this type is available, the preferred service - * for the serviceType and af if specified and if defined. - */ - public ServiceWithParameters getPreferredServiceFor(AlignFrame af, - String serviceName) - { - String serviceurl = null; - synchronized (preferredServiceMap) - { - String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); - Map prefmap = preferredServiceMap.get(afid); - if (afid.length() > 0 && prefmap == null) - { - // recover global setting, if any - prefmap = preferredServiceMap.get(""); - } - if (prefmap != null) - { - serviceurl = prefmap.get(serviceName); - } - - } - ServiceWithParameters response = null; - for (ServiceWithParameters svc : getServices()) - { - if (svc.getName().equals(serviceName)) - { - if (serviceurl == null || serviceurl.equals(svc.getHostURL())) - { - response = svc; - break; - } - } - } - return response; - } - - public void setPreferredServiceFor(AlignFrame af, String serviceName, - String serviceAction, ServiceWithParameters selectedServer) - { - // TODO: pull out and generalise for the selectedServer's attributes - String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); - if (preferredServiceMap == null) - { - preferredServiceMap = new HashMap<>(); - } - Map prefmap = preferredServiceMap.get(afid); - if (prefmap == null) - { - prefmap = new HashMap<>(); - preferredServiceMap.put(afid, prefmap); - } - prefmap.put(serviceName, selectedServer.getHostURL()); - prefmap.put(serviceAction, selectedServer.getHostURL()); - } - - public void setPreferredServiceFor(String serviceType, - String serviceAction, ServiceWithParameters selectedServer) - { - setPreferredServiceFor(null, serviceType, serviceAction, - selectedServer); - } - - /** * Set a URL to try before any others. For use with command-line parameter to * configure a local Jabaws installation without the need to add to property * files.