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.gui.JvOptionPane;
24 import jalview.util.MessageManager;
26 import java.util.Hashtable;
27 import java.util.StringTokenizer;
28 import java.util.Vector;
30 import ext.vamsas.IRegistry;
31 import ext.vamsas.IRegistryServiceLocator;
32 import ext.vamsas.RegistryServiceSoapBindingStub;
33 import ext.vamsas.ServiceHandle;
34 import ext.vamsas.ServiceHandles;
36 public class Discoverer implements Runnable
38 ext.vamsas.IRegistry registry; // the root registry service.
40 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
44 * change listeners are notified of "services" property changes
47 * to be added that consumes new services Hashtable object.
49 public void addPropertyChangeListener(
50 java.beans.PropertyChangeListener listener)
52 changeSupport.addPropertyChangeListener(listener);
61 public void removePropertyChangeListener(
62 java.beans.PropertyChangeListener listener)
64 changeSupport.removePropertyChangeListener(listener);
68 * Property change listener firing routine
77 public void firePropertyChange(String prop, Object oldvalue,
80 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
84 * Initializes the server field with a valid service implementation.
86 * @return true if service was located.
88 private IRegistry locateWebService(java.net.URL WsURL)
90 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
91 IRegistry server = null;
94 server = loc.getRegistryService(WsURL);
95 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
98 } catch (Exception ex)
100 jalview.bin.Cache.log.error(
101 "Serious! Service location failed\nfor URL :" + WsURL + "\n",
107 loc.getEngine().setOption("axis", "1");
112 static private java.net.URL RootServiceURL = null;
114 static public Vector ServiceURLList = null;
116 static private boolean reallyDiscoverServices = true;
118 public static java.util.Hashtable services = null; // vectors of services
121 // abstractServiceType
124 public static java.util.Vector serviceList = null; // flat list of services
126 static private Vector getDiscoveryURLS()
128 Vector urls = new Vector();
129 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
130 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
134 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
135 while (st.hasMoreElements())
140 java.net.URL u = new java.net.URL(url = st.nextToken());
141 if (!urls.contains(u))
147 jalview.bin.Cache.log
148 .info("Ignoring duplicate url in DISCOVERY_URLS list");
150 } catch (Exception ex)
152 jalview.bin.Cache.log
153 .warn("Problem whilst trying to make a URL from '"
154 + ((url != null) ? url : "<null>") + "'");
155 jalview.bin.Cache.log.warn(
156 "This was probably due to a malformed comma separated list"
157 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
158 jalview.bin.Cache.log.debug("Exception was ", ex);
161 } catch (Exception ex)
163 jalview.bin.Cache.log.warn(
164 "Error parsing comma separated list of urls in DISCOVERY_URLS.",
175 * fetch new services or reset to hardwired defaults depending on preferences.
177 static public void doDiscovery()
179 jalview.bin.Cache.log
180 .debug("(Re)-Initialising the discovery URL list.");
183 reallyDiscoverServices = jalview.bin.Cache
184 .getDefault("DISCOVERY_START", false);
185 if (reallyDiscoverServices)
187 ServiceURLList = getDiscoveryURLS();
191 jalview.bin.Cache.log.debug("Setting default services");
192 services = new Hashtable();
193 // Muscle, Clustal and JPred.
194 ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
195 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
196 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
197 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
198 MessageManager.getString(
199 "label.muscle_multiple_protein_sequence_alignment")),
200 new ServiceHandle("MsaWS",
201 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
202 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
203 + " Nucleic Acids Research, 33 511-518",
204 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
205 MessageManager.getString(
206 "label.mafft_multiple_sequence_alignment")),
207 new ServiceHandle("MsaWS",
208 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
209 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
210 + " Nucleic Acids Research, 22 4673-4680",
211 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
212 MessageManager.getString(
213 "label.clustalw_multiple_sequence_alignment")),
214 new ServiceHandle("SecStrPred",
215 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
216 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
217 + "\ndoi://10.1093/nar/gkv332",
218 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
219 "JPred Secondary Structure Prediction") };
220 services = new Hashtable();
221 serviceList = new Vector();
222 buildServiceLists(defServices, serviceList, services);
225 } catch (Exception e)
228 "jalview.rootRegistry is not a proper url!\nWas set to "
229 + RootServiceURL + "\n" + e);
234 // TODO: JBPNote : make this discover more services based on list of
235 // discovery service urls, break cyclic references to the same url and
236 // duplicate service entries (same endpoint *and* same interface)
237 private ServiceHandle[] getServices(java.net.URL location)
239 ServiceHandles shs = null;
242 jalview.bin.Cache.log.debug("Discovering services using " + location);
243 shs = locateWebService(location).getServices();
244 } catch (org.apache.axis.AxisFault f)
246 // JBPNote - should do this a better way!
247 if (f.getFaultReason().indexOf("(407)") > -1)
249 if (jalview.gui.Desktop.desktop != null)
251 JvOptionPane.showMessageDialog(jalview.gui.Desktop.desktop,
252 MessageManager.getString("label.set_proxy_settings"),
254 .getString("label.proxy_authorization_failed"),
255 JvOptionPane.WARNING_MESSAGE);
260 jalview.bin.Cache.log.warn("No Discovery service at " + location);
261 jalview.bin.Cache.log.debug("Axis Fault", f);
263 } catch (Exception e)
265 jalview.bin.Cache.log.warn("No Discovery service at " + location);
266 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
268 if ((shs != null) && shs.getServices().length > 0)
270 return shs.getServices();
276 * Adds a list of services to the service catalog and categorised catalog
277 * returns true if ServiceURLList was modified with a new DiscoveryService URL
287 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
290 boolean seenNewDiscovery = false;
291 for (int i = 0, j = sh.length; i < j; i++)
293 if (!cat.contains(sh[i]))
295 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
296 + " service called " + sh[i].getName() + " exists at "
297 + sh[i].getEndpointURL() + "\n");
298 if (!sscat.containsKey(sh[i].getAbstractName()))
300 sscat.put(sh[i].getAbstractName(), cat = new Vector());
304 cat = (Vector) sscat.get(sh[i].getAbstractName());
307 if (sh[i].getAbstractName().equals("Registry"))
309 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
311 java.net.URL disc_serv = null;
314 disc_serv = new java.net.URL(sh[i].getEndpointURL());
315 if (!ServiceURLList.contains(disc_serv))
317 jalview.bin.Cache.log.debug(
318 "Adding new discovery service at " + disc_serv);
319 ServiceURLList.add(disc_serv);
320 seenNewDiscovery = true;
322 } catch (Exception e)
324 jalview.bin.Cache.log
325 .debug("Ignoring bad discovery service URL "
326 + sh[i].getEndpointURL(), e);
332 return seenNewDiscovery;
335 public void discoverServices()
337 Hashtable sscat = new Hashtable();
338 Vector cat = new Vector();
339 ServiceHandle sh[] = null;
341 if (ServiceURLList == null)
343 jalview.bin.Cache.log
344 .debug("No service endpoints to use for service discovery.");
347 while (s_url < ServiceURLList.size())
349 if ((sh = getServices(
350 (java.net.URL) ServiceURLList.get(s_url))) != null)
353 buildServiceLists(sh, cat, sscat);
357 jalview.bin.Cache.log.warn("No services at "
358 + (ServiceURLList.get(s_url))
359 + " - check DISCOVERY_URLS property in .jalview_properties");
363 // TODO: decide on correct semantics for services list - PropertyChange
364 // provides a way of passing the new object around
365 // so no need to access original discovery thread.
366 // Curent decision is to change properties then notify listeners with old
368 Hashtable oldServices = services;
369 // Vector oldServicelist = serviceList;
372 changeSupport.firePropertyChange("services", oldServices, services);
376 * creates a new thread to call discoverServices()
381 final Discoverer discoverer = this;
382 Thread discoverThread = new Thread()
387 discoverer.doDiscovery();
388 discoverer.discoverServices();
391 discoverThread.start();
395 * binding service abstract name to handler class
397 private static Hashtable serviceClientBindings;
399 public static WS1Client getServiceClient(ServiceHandle sh)
401 if (serviceClientBindings == null)
403 // get a list from Config or create below
404 serviceClientBindings = new Hashtable();
405 serviceClientBindings.put("MsaWS", new MsaWSClient());
406 serviceClientBindings.put("SecStrPred", new JPredClient());
407 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
409 WS1Client instance = (WS1Client) serviceClientBindings
410 .get(sh.getAbstractName());
411 if (instance == null)
414 "WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
415 + sh.getAbstractName());
419 instance.serviceHandle = sh;
424 * notes on discovery service 1. need to allow multiple discovery source urls.
425 * 2. user interface to add/control list of urls in preferences notes on
426 * wsclient discovery 1. need a classpath property with list of additional
427 * plugin directories 2. optional config to cite specific bindings between
428 * class name and Abstract service name. 3. precedence for automatic discovery
429 * by using getAbstractName for WSClient - user added plugins override default
430 * plugins ? notes on wsclient gui code for gui attachment now moved to
431 * wsclient implementation. Needs more abstraction but approach seems to work.
432 * is it possible to 'generalise' the data retrieval calls further ? current
433 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
434 * new methods for conservation (group or alignment), treecalc (aligned
435 * profile), seqannot (sequences selected from dataset, annotation back to