2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws1;
23 import jalview.bin.Cache;
24 import jalview.gui.JvOptionPane;
25 import jalview.util.MessageManager;
28 import java.util.Hashtable;
29 import java.util.StringTokenizer;
30 import java.util.Vector;
32 import ext.vamsas.IRegistry;
33 import ext.vamsas.IRegistryServiceLocator;
34 import ext.vamsas.RegistryServiceSoapBindingStub;
35 import ext.vamsas.ServiceHandle;
36 import ext.vamsas.ServiceHandles;
38 public class Discoverer implements Runnable
40 ext.vamsas.IRegistry registry; // the root registry service.
42 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
46 * change listeners are notified of "services" property changes
49 * to be added that consumes new services Hashtable object.
51 public void addPropertyChangeListener(
52 java.beans.PropertyChangeListener listener)
54 changeSupport.addPropertyChangeListener(listener);
63 public void removePropertyChangeListener(
64 java.beans.PropertyChangeListener listener)
66 changeSupport.removePropertyChangeListener(listener);
70 * Property change listener firing routine
79 public void firePropertyChange(String prop, Object oldvalue,
82 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
86 * Initializes the server field with a valid service implementation.
88 * @return true if service was located.
90 private IRegistry locateWebService(java.net.URL WsURL)
92 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
93 IRegistry server = null;
96 server = loc.getRegistryService(WsURL);
97 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
100 } catch (Exception ex)
102 jalview.bin.Cache.log.error(
103 "Serious! Service location failed\nfor URL :" + WsURL + "\n",
109 loc.getEngine().setOption("axis", "1");
114 static private java.net.URL RootServiceURL = null;
116 static public Vector<URL> ServiceURLList = null;
118 static private boolean reallyDiscoverServices = true;
120 public static java.util.Hashtable<String, Vector<ServiceHandle>> services = null;
122 // abstractServiceType
125 public static java.util.Vector<ServiceHandle> serviceList = null;
127 static private Vector<URL> getDiscoveryURLS()
129 Vector<URL> urls = new Vector<>();
130 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
131 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
135 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
136 while (st.hasMoreElements())
141 java.net.URL u = new java.net.URL(url = st.nextToken());
142 if (!urls.contains(u))
148 jalview.bin.Cache.log
149 .info("Ignoring duplicate url in DISCOVERY_URLS list");
151 } catch (Exception ex)
153 jalview.bin.Cache.log
154 .warn("Problem whilst trying to make a URL from '"
155 + ((url != null) ? url : "<null>") + "'");
156 jalview.bin.Cache.log.warn(
157 "This was probably due to a malformed comma separated list"
158 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
159 jalview.bin.Cache.log.debug("Exception was ", ex);
162 } catch (Exception ex)
164 jalview.bin.Cache.log.warn(
165 "Error parsing comma separated list of urls in DISCOVERY_URLS.",
176 * fetch new services or reset to hardwired defaults depending on preferences.
178 static public void doDiscovery()
180 jalview.bin.Cache.log
181 .debug("(Re)-Initialising the discovery URL list.");
184 reallyDiscoverServices = jalview.bin.Cache
185 .getDefault("DISCOVERY_START", false);
186 if (reallyDiscoverServices)
188 ServiceURLList = getDiscoveryURLS();
192 jalview.bin.Cache.log.debug("Setting default services");
193 services = new Hashtable<>();
194 // Muscle, Clustal and JPred.
195 ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
196 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
197 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
198 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
199 MessageManager.getString(
200 "label.muscle_multiple_protein_sequence_alignment")),
201 new ServiceHandle("MsaWS",
202 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
203 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
204 + " Nucleic Acids Research, 33 511-518",
205 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
206 MessageManager.getString(
207 "label.mafft_multiple_sequence_alignment")),
208 new ServiceHandle("MsaWS",
209 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
210 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
211 + " Nucleic Acids Research, 22 4673-4680",
212 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
213 MessageManager.getString(
214 "label.clustalw_multiple_sequence_alignment")),
215 new ServiceHandle("SecStrPred",
216 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
217 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
218 + "\ndoi://10.1093/nar/gkv332",
219 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
220 "JPred Secondary Structure Prediction") };
221 services = new Hashtable<>();
222 serviceList = new Vector<>();
223 buildServiceLists(defServices, serviceList, services);
226 } catch (Exception e)
229 "jalview.rootRegistry is not a proper url!\nWas set to "
230 + RootServiceURL + "\n" + e);
235 // TODO: JBPNote : make this discover more services based on list of
236 // discovery service urls, break cyclic references to the same url and
237 // duplicate service entries (same endpoint *and* same interface)
238 private ServiceHandle[] getServices(java.net.URL location)
240 ServiceHandles shs = null;
243 jalview.bin.Cache.log.debug("Discovering services using " + location);
244 shs = locateWebService(location).getServices();
245 } catch (org.apache.axis.AxisFault f)
247 // JBPNote - should do this a better way!
248 if (f.getFaultReason().indexOf("(407)") > -1)
250 if (jalview.gui.Desktop.desktop != null)
252 JvOptionPane.showMessageDialog(jalview.gui.Desktop.desktop,
253 MessageManager.getString("label.set_proxy_settings"),
255 .getString("label.proxy_authorization_failed"),
256 JvOptionPane.WARNING_MESSAGE);
261 jalview.bin.Cache.log.warn("No Discovery service at " + location);
262 jalview.bin.Cache.log.debug("Axis Fault", f);
264 } catch (Exception e)
266 jalview.bin.Cache.log.warn("No Discovery service at " + location);
267 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
269 if ((shs != null) && shs.getServices().length > 0)
271 return shs.getServices();
277 * Adds a list of services to the service catalog and categorised catalog
278 * returns true if ServiceURLList was modified with a new DiscoveryService URL
288 static private boolean buildServiceLists(ServiceHandle[] sh,
289 Vector<ServiceHandle> cat,
290 Hashtable<String, Vector<ServiceHandle>> sscat)
292 boolean seenNewDiscovery = false;
293 for (int i = 0, j = sh.length; i < j; i++)
295 if (!cat.contains(sh[i]))
297 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
298 + " service called " + sh[i].getName() + " exists at "
299 + sh[i].getEndpointURL() + "\n");
300 if (!sscat.containsKey(sh[i].getAbstractName()))
302 sscat.put(sh[i].getAbstractName(), cat = new Vector<>());
306 cat = sscat.get(sh[i].getAbstractName());
309 if (sh[i].getAbstractName().equals("Registry"))
311 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
313 java.net.URL disc_serv = null;
316 disc_serv = new java.net.URL(sh[i].getEndpointURL());
317 if (!ServiceURLList.contains(disc_serv))
319 jalview.bin.Cache.log.debug(
320 "Adding new discovery service at " + disc_serv);
321 ServiceURLList.add(disc_serv);
322 seenNewDiscovery = true;
324 } catch (Exception e)
326 jalview.bin.Cache.log
327 .debug("Ignoring bad discovery service URL "
328 + sh[i].getEndpointURL(), e);
334 return seenNewDiscovery;
337 public void discoverServices()
339 Hashtable<String, Vector<ServiceHandle>> sscat = new Hashtable<>();
340 Vector<ServiceHandle> cat = new Vector<>();
341 ServiceHandle sh[] = null;
343 if (ServiceURLList == null)
345 jalview.bin.Cache.log
346 .debug("No service endpoints to use for service discovery.");
349 while (s_url < ServiceURLList.size())
351 if ((sh = getServices(
352 ServiceURLList.get(s_url))) != null)
355 buildServiceLists(sh, cat, sscat);
359 jalview.bin.Cache.log.warn("No services at "
360 + (ServiceURLList.get(s_url))
361 + " - check DISCOVERY_URLS property in .jalview_properties");
365 // TODO: decide on correct semantics for services list - PropertyChange
366 // provides a way of passing the new object around
367 // so no need to access original discovery thread.
368 // Curent decision is to change properties then notify listeners with old
370 Hashtable<String, Vector<ServiceHandle>> oldServices = services;
371 // Vector oldServicelist = serviceList;
374 changeSupport.firePropertyChange("services", oldServices, services);
378 * creates a new thread to call discoverServices()
383 Cache.log.info("Discovering jws1 services");
384 Discoverer.doDiscovery();
389 * binding service abstract name to handler class
391 private static Hashtable<String, WS1Client> serviceClientBindings;
393 public static WS1Client getServiceClient(ServiceHandle sh)
395 if (serviceClientBindings == null)
397 // get a list from Config or create below
398 serviceClientBindings = new Hashtable<>();
399 serviceClientBindings.put("MsaWS", new MsaWSClient());
400 serviceClientBindings.put("SecStrPred", new JPredClient());
401 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
403 WS1Client instance = serviceClientBindings
404 .get(sh.getAbstractName());
405 if (instance == null)
408 "WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
409 + sh.getAbstractName());
413 instance.serviceHandle = sh;
418 * notes on discovery service 1. need to allow multiple discovery source urls.
419 * 2. user interface to add/control list of urls in preferences notes on
420 * wsclient discovery 1. need a classpath property with list of additional
421 * plugin directories 2. optional config to cite specific bindings between
422 * class name and Abstract service name. 3. precedence for automatic discovery
423 * by using getAbstractName for WSClient - user added plugins override default
424 * plugins ? notes on wsclient gui code for gui attachment now moved to
425 * wsclient implementation. Needs more abstraction but approach seems to work.
426 * is it possible to 'generalise' the data retrieval calls further ? current
427 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
428 * new methods for conservation (group or alignment), treecalc (aligned
429 * profile), seqannot (sequences selected from dataset, annotation back to