2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
3 * Copyright (C) 2014 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.util.MessageManager;
31 public class Discoverer implements Runnable
33 ext.vamsas.IRegistry registry; // the root registry service.
35 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
39 * change listeners are notified of "services" property changes
42 * to be added that consumes new services Hashtable object.
44 public void addPropertyChangeListener(
45 java.beans.PropertyChangeListener listener)
47 changeSupport.addPropertyChangeListener(listener);
56 public void removePropertyChangeListener(
57 java.beans.PropertyChangeListener listener)
59 changeSupport.removePropertyChangeListener(listener);
63 * Property change listener firing routine
72 public void firePropertyChange(String prop, Object oldvalue,
75 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
79 * Initializes the server field with a valid service implementation.
81 * @return true if service was located.
83 private IRegistry locateWebService(java.net.URL WsURL)
85 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
86 IRegistry server = null;
89 server = loc.getRegistryService(WsURL);
90 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
93 } catch (Exception ex)
96 .error("Serious! Service location failed\nfor URL :" + WsURL
102 loc.getEngine().setOption("axis", "1");
107 static private java.net.URL RootServiceURL = null;
109 static public Vector ServiceURLList = null;
111 static private boolean reallyDiscoverServices = true;
113 public static java.util.Hashtable services = null; // vectors of services
116 // abstractServiceType
119 public static java.util.Vector serviceList = null; // flat list of services
121 static private Vector getDiscoveryURLS()
123 Vector urls = new Vector();
124 String RootServiceURLs = jalview.bin.Cache
125 .getDefault("DISCOVERY_URLS",
126 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
130 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
131 while (st.hasMoreElements())
136 java.net.URL u = new java.net.URL(url = st.nextToken());
137 if (!urls.contains(u))
143 jalview.bin.Cache.log
144 .info("Ignoring duplicate url in DISCOVERY_URLS list");
146 } catch (Exception ex)
148 jalview.bin.Cache.log
149 .warn("Problem whilst trying to make a URL from '"
150 + ((url != null) ? url : "<null>") + "'");
151 jalview.bin.Cache.log
152 .warn("This was probably due to a malformed comma separated list"
153 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
154 jalview.bin.Cache.log.debug("Exception was ", ex);
157 } catch (Exception ex)
159 jalview.bin.Cache.log
160 .warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",
171 * fetch new services or reset to hardwired defaults depending on preferences.
173 static public void doDiscovery()
175 jalview.bin.Cache.log
176 .debug("(Re)-Initialising the discovery URL list.");
179 reallyDiscoverServices = jalview.bin.Cache.getDefault(
180 "DISCOVERY_START", false);
181 if (reallyDiscoverServices)
183 ServiceURLList = getDiscoveryURLS();
187 jalview.bin.Cache.log.debug("Setting default services");
188 services = new Hashtable();
189 // Muscle, Clustal and JPred.
190 ServiceHandle[] defServices =
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("label.muscle_multiple_protein_sequence_alignment")),
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("label.mafft_multiple_sequence_alignment")),
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("label.clustalw_multiple_sequence_alignment")),
214 "Cole C., Barber J. D., Barton G.J (2008) "
215 + "The Jpred 3 secondary structure prediction server "
216 + "Nucleic Acids Research, 36 W197-W201",
217 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
218 "JNet Secondary Structure Prediction") };
219 services = new Hashtable();
220 serviceList = new Vector();
221 buildServiceLists(defServices, serviceList, services);
224 } catch (Exception e)
227 .println("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 jalview.bin.Cache.log.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)
252 jalview.gui.Desktop.desktop,
253 MessageManager.getString("label.set_proxy_settings"),
254 MessageManager.getString("label.proxy_authorization_failed"),
255 JOptionPane.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
318 .debug("Adding new discovery service at "
320 ServiceURLList.add(disc_serv);
321 seenNewDiscovery = true;
323 } catch (Exception e)
325 jalview.bin.Cache.log.debug(
326 "Ignoring bad discovery service URL "
327 + sh[i].getEndpointURL(), e);
333 return seenNewDiscovery;
336 public void discoverServices()
338 Hashtable sscat = new Hashtable();
339 Vector cat = new Vector();
340 ServiceHandle sh[] = null;
342 if (ServiceURLList == null)
344 jalview.bin.Cache.log
345 .debug("No service endpoints to use for service discovery.");
348 while (s_url < ServiceURLList.size())
350 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
353 buildServiceLists(sh, cat, sscat);
357 jalview.bin.Cache.log
358 .warn("No services at "
359 + ((java.net.URL) ServiceURLList.get(s_url))
360 + " - check DISCOVERY_URLS property in .jalview_properties");
364 // TODO: decide on correct semantics for services list - PropertyChange
365 // provides a way of passing the new object around
366 // so no need to access original discovery thread.
367 // Curent decision is to change properties then notify listeners with old
369 Hashtable oldServices = services;
370 // Vector oldServicelist = serviceList;
373 changeSupport.firePropertyChange("services", oldServices, services);
377 * creates a new thread to call discoverServices()
381 final Discoverer discoverer = this;
382 Thread discoverThread = new Thread()
386 discoverer.doDiscovery();
387 discoverer.discoverServices();
390 discoverThread.start();
394 * binding service abstract name to handler class
396 private static Hashtable serviceClientBindings;
398 public static WS1Client getServiceClient(ServiceHandle sh)
400 if (serviceClientBindings == null)
402 // get a list from Config or create below
403 serviceClientBindings = new Hashtable();
404 serviceClientBindings.put("MsaWS", new MsaWSClient());
405 serviceClientBindings.put("SecStrPred", new JPredClient());
406 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
408 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
410 if (instance == null)
413 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
414 + sh.getAbstractName());
418 instance.serviceHandle = sh;
423 * notes on discovery service 1. need to allow multiple discovery source urls.
424 * 2. user interface to add/control list of urls in preferences notes on
425 * wsclient discovery 1. need a classpath property with list of additional
426 * plugin directories 2. optional config to cite specific bindings between
427 * class name and Abstract service name. 3. precedence for automatic discovery
428 * by using getAbstractName for WSClient - user added plugins override default
429 * plugins ? notes on wsclient gui code for gui attachment now moved to
430 * wsclient implementation. Needs more abstraction but approach seems to work.
431 * is it possible to 'generalise' the data retrieval calls further ? current
432 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
433 * new methods for conservation (group or alignment), treecalc (aligned
434 * profile), seqannot (sequences selected from dataset, annotation back to