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.Jalview;
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
41 public static Discoverer getInstance()
43 Jalview j = Jalview.getInstance();
44 return (j.discoverer == null ? j.discoverer = new Discoverer()
48 private java.net.URL RootServiceURL = null;
50 private Vector<URL> ServiceURLList = null;
52 private boolean reallyDiscoverServices = true;
54 private Hashtable<String, Vector<ServiceHandle>> services = null;
56 public Hashtable<String, Vector<ServiceHandle>> getServices()
61 private Vector<ServiceHandle> serviceList = null;
63 // private ext.vamsas.IRegistry registry; // the root registry service.
66 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
70 * change listeners are notified of "services" property changes
73 * to be added that consumes new services Hashtable object.
75 public void addPropertyChangeListener(
76 java.beans.PropertyChangeListener listener)
78 changeSupport.addPropertyChangeListener(listener);
87 public void removePropertyChangeListener(
88 java.beans.PropertyChangeListener listener)
90 changeSupport.removePropertyChangeListener(listener);
94 * Property change listener firing routine
103 public void firePropertyChange(String prop, Object oldvalue,
106 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
110 * Initializes the server field with a valid service implementation.
112 * @return true if service was located.
114 private IRegistry locateWebService(java.net.URL WsURL)
116 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
117 IRegistry server = null;
120 server = loc.getRegistryService(WsURL);
121 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
124 } catch (Exception ex)
126 jalview.bin.Cache.log.error(
127 "Serious! Service location failed\nfor URL :" + WsURL + "\n",
133 loc.getEngine().setOption("axis", "1");
138 static private Vector<URL> getDiscoveryURLS()
140 Vector<URL> urls = new Vector<>();
141 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
142 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
146 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
147 while (st.hasMoreElements())
152 java.net.URL u = new java.net.URL(url = st.nextToken());
153 if (!urls.contains(u))
159 jalview.bin.Cache.log
160 .info("Ignoring duplicate url in DISCOVERY_URLS list");
162 } catch (Exception ex)
164 jalview.bin.Cache.log
165 .warn("Problem whilst trying to make a URL from '"
166 + ((url != null) ? url : "<null>") + "'");
167 jalview.bin.Cache.log.warn(
168 "This was probably due to a malformed comma separated list"
169 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
170 jalview.bin.Cache.log.debug("Exception was ", ex);
173 } catch (Exception ex)
175 jalview.bin.Cache.log.warn(
176 "Error parsing comma separated list of urls in DISCOVERY_URLS.",
187 * fetch new services or reset to hardwired defaults depending on preferences.
189 static public void doDiscovery()
191 jalview.bin.Cache.log
192 .debug("(Re)-Initialising the discovery URL list.");
193 Discoverer d = getInstance();
196 d.reallyDiscoverServices = jalview.bin.Cache
197 .getDefault("DISCOVERY_START", false);
198 if (d.reallyDiscoverServices)
200 d.ServiceURLList = getDiscoveryURLS();
204 jalview.bin.Cache.log.debug("Setting default services");
205 d.services = new Hashtable<>();
206 // Muscle, Clustal and JPred.
207 ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
208 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
209 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
210 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
211 MessageManager.getString(
212 "label.muscle_multiple_protein_sequence_alignment")),
213 new ServiceHandle("MsaWS",
214 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
215 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
216 + " Nucleic Acids Research, 33 511-518",
217 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
218 MessageManager.getString(
219 "label.mafft_multiple_sequence_alignment")),
220 new ServiceHandle("MsaWS",
221 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
222 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
223 + " Nucleic Acids Research, 22 4673-4680",
224 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
225 MessageManager.getString(
226 "label.clustalw_multiple_sequence_alignment")),
227 new ServiceHandle("SecStrPred",
228 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
229 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
230 + "\ndoi://10.1093/nar/gkv332",
231 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
232 "JPred Secondary Structure Prediction") };
233 d.services = new Hashtable<>();
234 d.serviceList = new Vector<>();
235 buildServiceLists(defServices, d.serviceList, d.services);
238 } catch (Exception e)
241 "jalview.rootRegistry is not a proper url!\nWas set to "
242 + d.RootServiceURL + "\n" + e);
247 // TODO: JBPNote : make this discover more services based on list of
248 // discovery service urls, break cyclic references to the same url and
249 // duplicate service entries (same endpoint *and* same interface)
250 private ServiceHandle[] getServices(java.net.URL location)
252 ServiceHandles shs = null;
255 jalview.bin.Cache.log.debug("Discovering services using " + location);
256 shs = locateWebService(location).getServices();
257 } catch (org.apache.axis.AxisFault f)
259 // JBPNote - should do this a better way!
260 if (f.getFaultReason().indexOf("(407)") > -1)
262 if (jalview.gui.Desktop.getDesktopPane() != null)
264 JvOptionPane.showMessageDialog(jalview.gui.Desktop.getDesktopPane(),
265 MessageManager.getString("label.set_proxy_settings"),
267 .getString("label.proxy_authorization_failed"),
268 JvOptionPane.WARNING_MESSAGE);
273 jalview.bin.Cache.log.warn("No Discovery service at " + location);
274 jalview.bin.Cache.log.debug("Axis Fault", f);
276 } catch (Exception e)
278 jalview.bin.Cache.log.warn("No Discovery service at " + location);
279 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
281 if ((shs != null) && shs.getServices().length > 0)
283 return shs.getServices();
289 * Adds a list of services to the service catalog and categorised catalog
290 * returns true if ServiceURLList was modified with a new DiscoveryService URL
300 static private boolean buildServiceLists(ServiceHandle[] sh,
301 Vector<ServiceHandle> cat,
302 Hashtable<String, Vector<ServiceHandle>> sscat)
304 boolean seenNewDiscovery = false;
305 for (int i = 0, j = sh.length; i < j; i++)
307 if (!cat.contains(sh[i]))
309 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
310 + " service called " + sh[i].getName() + " exists at "
311 + sh[i].getEndpointURL() + "\n");
312 if (!sscat.containsKey(sh[i].getAbstractName()))
314 sscat.put(sh[i].getAbstractName(), cat = new Vector<>());
318 cat = sscat.get(sh[i].getAbstractName());
321 if (sh[i].getAbstractName().equals("Registry"))
323 Vector<URL> list = getInstance().ServiceURLList;
324 for (int s = 0, sUrls = list.size(); s < sUrls; s++)
326 java.net.URL disc_serv = null;
329 disc_serv = new java.net.URL(sh[i].getEndpointURL());
330 if (!list.contains(disc_serv))
332 jalview.bin.Cache.log.debug(
333 "Adding new discovery service at " + disc_serv);
335 seenNewDiscovery = true;
337 } catch (Exception e)
339 jalview.bin.Cache.log
340 .debug("Ignoring bad discovery service URL "
341 + sh[i].getEndpointURL(), e);
347 return seenNewDiscovery;
350 public void discoverServices()
352 Hashtable<String, Vector<ServiceHandle>> sscat = new Hashtable<>();
353 Vector<ServiceHandle> cat = new Vector<>();
354 ServiceHandle sh[] = null;
356 if (ServiceURLList == null)
358 jalview.bin.Cache.log
359 .debug("No service endpoints to use for service discovery.");
362 while (s_url < ServiceURLList.size())
364 if ((sh = getServices(
365 ServiceURLList.get(s_url))) != null)
368 buildServiceLists(sh, cat, sscat);
372 jalview.bin.Cache.log.warn("No services at "
373 + (ServiceURLList.get(s_url))
374 + " - check DISCOVERY_URLS property in .jalview_properties");
378 // TODO: decide on correct semantics for services list - PropertyChange
379 // provides a way of passing the new object around
380 // so no need to access original discovery thread.
381 // Curent decision is to change properties then notify listeners with old
383 Hashtable<String, Vector<ServiceHandle>> oldServices = services;
384 // Vector oldServicelist = serviceList;
387 changeSupport.firePropertyChange("services", oldServices, services);
391 * creates a new thread to call discoverServices()
396 final Discoverer discoverer = this;
397 Thread discoverThread = new Thread()
402 Discoverer.doDiscovery();
403 discoverer.discoverServices();
406 discoverThread.start();
410 * binding service abstract name to handler class
412 private static Hashtable<String, WS1Client> serviceClientBindings;
414 public static WS1Client getServiceClient(ServiceHandle sh)
416 if (serviceClientBindings == null)
418 // get a list from Config or create below
419 serviceClientBindings = new Hashtable<>();
420 serviceClientBindings.put("MsaWS", new MsaWSClient());
421 serviceClientBindings.put("SecStrPred", new JPredClient());
422 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
424 WS1Client instance = serviceClientBindings
425 .get(sh.getAbstractName());
426 if (instance == null)
429 "WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
430 + sh.getAbstractName());
434 instance.serviceHandle = sh;
439 * notes on discovery service 1. need to allow multiple discovery source urls.
440 * 2. user interface to add/control list of urls in preferences notes on
441 * wsclient discovery 1. need a classpath property with list of additional
442 * plugin directories 2. optional config to cite specific bindings between
443 * class name and Abstract service name. 3. precedence for automatic discovery
444 * by using getAbstractName for WSClient - user added plugins override default
445 * plugins ? notes on wsclient gui code for gui attachment now moved to
446 * wsclient implementation. Needs more abstraction but approach seems to work.
447 * is it possible to 'generalise' the data retrieval calls further ? current
448 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
449 * new methods for conservation (group or alignment), treecalc (aligned
450 * profile), seqannot (sequences selected from dataset, annotation back to