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.bin.Console;
25 import jalview.gui.JvOptionPane;
26 import jalview.util.MessageManager;
29 import java.util.Hashtable;
30 import java.util.StringTokenizer;
31 import java.util.Vector;
33 import ext.vamsas.IRegistry;
34 import ext.vamsas.IRegistryServiceLocator;
35 import ext.vamsas.RegistryServiceSoapBindingStub;
36 import ext.vamsas.ServiceHandle;
37 import ext.vamsas.ServiceHandles;
39 public class Discoverer implements Runnable
41 ext.vamsas.IRegistry registry; // the root registry service.
43 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
47 * change listeners are notified of "services" property changes
50 * to be added that consumes new services Hashtable object.
52 public void addPropertyChangeListener(
53 java.beans.PropertyChangeListener listener)
55 changeSupport.addPropertyChangeListener(listener);
64 public void removePropertyChangeListener(
65 java.beans.PropertyChangeListener listener)
67 changeSupport.removePropertyChangeListener(listener);
71 * Property change listener firing routine
80 public void firePropertyChange(String prop, Object oldvalue,
83 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
87 * Initializes the server field with a valid service implementation.
89 * @return true if service was located.
91 private IRegistry locateWebService(java.net.URL WsURL)
93 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
94 IRegistry server = null;
97 server = loc.getRegistryService(WsURL);
98 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
101 } catch (Exception ex)
104 "Serious! Service location failed\nfor URL :" + WsURL + "\n",
110 loc.getEngine().setOption("axis", "1");
115 static private java.net.URL RootServiceURL = null;
117 static public Vector<URL> ServiceURLList = null;
119 static private boolean reallyDiscoverServices = true;
121 public static java.util.Hashtable<String, Vector<ServiceHandle>> services = null;
123 // abstractServiceType
126 public static java.util.Vector<ServiceHandle> serviceList = null;
128 static private Vector<URL> getDiscoveryURLS()
130 Vector<URL> urls = new Vector<>();
131 String RootServiceURLs = Cache.getDefault("DISCOVERY_URLS",
132 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
136 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
137 while (st.hasMoreElements())
142 java.net.URL u = new java.net.URL(url = st.nextToken());
143 if (!urls.contains(u))
149 Console.info("Ignoring duplicate url in DISCOVERY_URLS list");
151 } catch (Exception ex)
153 Console.warn("Problem whilst trying to make a URL from '"
154 + ((url != null) ? url : "<null>") + "'");
156 "This was probably due to a malformed comma separated list"
157 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
158 Console.debug("Exception was ", ex);
161 } catch (Exception ex)
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 Console.debug("(Re)-Initialising the discovery URL list.");
182 reallyDiscoverServices = Cache
183 .getDefault("DISCOVERY_START", false);
184 if (reallyDiscoverServices)
186 ServiceURLList = getDiscoveryURLS();
190 Console.debug("Setting default services");
191 services = new Hashtable<>();
192 // Muscle, Clustal and JPred.
193 ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
194 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
195 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
196 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
197 MessageManager.getString(
198 "label.muscle_multiple_protein_sequence_alignment")),
199 new ServiceHandle("MsaWS",
200 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
201 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
202 + " Nucleic Acids Research, 33 511-518",
203 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
204 MessageManager.getString(
205 "label.mafft_multiple_sequence_alignment")),
206 new ServiceHandle("MsaWS",
207 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
208 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
209 + " Nucleic Acids Research, 22 4673-4680",
210 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
211 MessageManager.getString(
212 "label.clustalw_multiple_sequence_alignment")),
213 new ServiceHandle("SecStrPred",
214 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
215 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
216 + "\ndoi://10.1093/nar/gkv332",
217 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
218 "JPred Secondary Structure Prediction") };
219 services = new Hashtable<>();
220 serviceList = new Vector<>();
221 buildServiceLists(defServices, serviceList, services);
224 } catch (Exception e)
227 "jalview.rootRegistry is not a proper url!\nWas set to "
228 + RootServiceURL + "\n" + e);
233 // TODO: JBPNote : make this discover more services based on list of
234 // discovery service urls, break cyclic references to the same url and
235 // duplicate service entries (same endpoint *and* same interface)
236 private ServiceHandle[] getServices(java.net.URL location)
238 ServiceHandles shs = null;
241 Console.debug("Discovering services using " + location);
242 shs = locateWebService(location).getServices();
243 } catch (org.apache.axis.AxisFault f)
245 // JBPNote - should do this a better way!
246 if (f.getFaultReason().indexOf("(407)") > -1)
248 if (jalview.gui.Desktop.desktop != null)
250 JvOptionPane.showMessageDialog(jalview.gui.Desktop.desktop,
251 MessageManager.getString("label.set_proxy_settings"),
253 .getString("label.proxy_authorization_failed"),
254 JvOptionPane.WARNING_MESSAGE);
259 Console.warn("No Discovery service at " + location);
260 Console.debug("Axis Fault", f);
262 } catch (Exception e)
264 Console.warn("No Discovery service at " + location);
265 Console.debug("Discovery Service General Exception", e);
267 if ((shs != null) && shs.getServices().length > 0)
269 return shs.getServices();
275 * Adds a list of services to the service catalog and categorised catalog
276 * returns true if ServiceURLList was modified with a new DiscoveryService URL
286 static private boolean buildServiceLists(ServiceHandle[] sh,
287 Vector<ServiceHandle> cat,
288 Hashtable<String, Vector<ServiceHandle>> sscat)
290 boolean seenNewDiscovery = false;
291 for (int i = 0, j = sh.length; i < j; i++)
293 if (!cat.contains(sh[i]))
295 Console.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 = 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))
318 "Adding new discovery service at " + disc_serv);
319 ServiceURLList.add(disc_serv);
320 seenNewDiscovery = true;
322 } catch (Exception e)
324 Console.debug("Ignoring bad discovery service URL "
325 + sh[i].getEndpointURL(), e);
331 return seenNewDiscovery;
334 public void discoverServices()
336 Hashtable<String, Vector<ServiceHandle>> sscat = new Hashtable<>();
337 Vector<ServiceHandle> cat = new Vector<>();
338 ServiceHandle sh[] = null;
340 if (ServiceURLList == null)
342 Console.debug("No service endpoints to use for service discovery.");
345 while (s_url < ServiceURLList.size())
347 if ((sh = getServices(
348 ServiceURLList.get(s_url))) != null)
351 buildServiceLists(sh, cat, sscat);
355 Console.warn("No services at "
356 + (ServiceURLList.get(s_url))
357 + " - check DISCOVERY_URLS property in .jalview_properties");
361 // TODO: decide on correct semantics for services list - PropertyChange
362 // provides a way of passing the new object around
363 // so no need to access original discovery thread.
364 // Curent decision is to change properties then notify listeners with old
366 Hashtable<String, Vector<ServiceHandle>> oldServices = services;
367 // Vector oldServicelist = serviceList;
370 changeSupport.firePropertyChange("services", oldServices, services);
374 * creates a new thread to call discoverServices()
379 final Discoverer discoverer = this;
380 Thread discoverThread = new Thread()
385 Discoverer.doDiscovery();
386 discoverer.discoverServices();
389 discoverThread.start();
393 * binding service abstract name to handler class
395 private static Hashtable<String, WS1Client> serviceClientBindings;
397 public static WS1Client getServiceClient(ServiceHandle sh)
399 if (serviceClientBindings == null)
401 // get a list from Config or create below
402 serviceClientBindings = new Hashtable<>();
403 serviceClientBindings.put("MsaWS", new MsaWSClient());
404 serviceClientBindings.put("SecStrPred", new JPredClient());
405 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
407 WS1Client instance = serviceClientBindings
408 .get(sh.getAbstractName());
409 if (instance == null)
412 "WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
413 + sh.getAbstractName());
417 instance.serviceHandle = sh;
422 * notes on discovery service 1. need to allow multiple discovery source urls.
423 * 2. user interface to add/control list of urls in preferences notes on
424 * wsclient discovery 1. need a classpath property with list of additional
425 * plugin directories 2. optional config to cite specific bindings between
426 * class name and Abstract service name. 3. precedence for automatic discovery
427 * by using getAbstractName for WSClient - user added plugins override default
428 * plugins ? notes on wsclient gui code for gui attachment now moved to
429 * wsclient implementation. Needs more abstraction but approach seems to work.
430 * is it possible to 'generalise' the data retrieval calls further ? current
431 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
432 * new methods for conservation (group or alignment), treecalc (aligned
433 * profile), seqannot (sequences selected from dataset, annotation back to