2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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;
29 public class Discoverer implements Runnable
31 ext.vamsas.IRegistry registry; // the root registry service.
33 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
37 * change listeners are notified of "services" property changes
40 * to be added that consumes new services Hashtable object.
42 public void addPropertyChangeListener(
43 java.beans.PropertyChangeListener listener)
45 changeSupport.addPropertyChangeListener(listener);
54 public void removePropertyChangeListener(
55 java.beans.PropertyChangeListener listener)
57 changeSupport.removePropertyChangeListener(listener);
61 * Property change listener firing routine
70 public void firePropertyChange(String prop, Object oldvalue,
73 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
77 * Initializes the server field with a valid service implementation.
79 * @return true if service was located.
81 private IRegistry locateWebService(java.net.URL WsURL)
83 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
84 IRegistry server = null;
87 server = loc.getRegistryService(WsURL);
88 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
91 } catch (Exception ex)
94 .error("Serious! Service location failed\nfor URL :" + WsURL
100 loc.getEngine().setOption("axis", "1");
105 static private java.net.URL RootServiceURL = null;
107 static public Vector ServiceURLList = null;
109 static private boolean reallyDiscoverServices = true;
111 public static java.util.Hashtable services = null; // vectors of services
114 // abstractServiceType
117 public static java.util.Vector serviceList = null; // flat list of services
119 static private Vector getDiscoveryURLS()
121 Vector urls = new Vector();
122 String RootServiceURLs = jalview.bin.Cache
123 .getDefault("DISCOVERY_URLS",
124 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
128 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
129 while (st.hasMoreElements())
134 java.net.URL u = new java.net.URL(url = st.nextToken());
135 if (!urls.contains(u))
141 jalview.bin.Cache.log
142 .info("Ignoring duplicate url in DISCOVERY_URLS list");
144 } catch (Exception ex)
146 jalview.bin.Cache.log
147 .warn("Problem whilst trying to make a URL from '"
148 + ((url != null) ? url : "<null>") + "'");
149 jalview.bin.Cache.log
150 .warn("This was probably due to a malformed comma separated list"
151 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
152 jalview.bin.Cache.log.debug("Exception was ", ex);
155 } catch (Exception ex)
157 jalview.bin.Cache.log
158 .warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",
169 * fetch new services or reset to hardwired defaults depending on preferences.
171 static public void doDiscovery()
173 jalview.bin.Cache.log
174 .debug("(Re)-Initialising the discovery URL list.");
177 reallyDiscoverServices = jalview.bin.Cache.getDefault(
178 "DISCOVERY_START", false);
179 if (reallyDiscoverServices)
181 ServiceURLList = getDiscoveryURLS();
185 jalview.bin.Cache.log.debug("Setting default services");
186 services = new Hashtable();
187 // Muscle, Clustal and JPred.
188 ServiceHandle[] defServices =
192 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
193 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
194 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
195 "Muscle Multiple Protein Sequence Alignment"),
198 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
199 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
200 + " Nucleic Acids Research, 33 511-518",
201 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
202 "MAFFT Multiple Sequence Alignment"),
205 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
206 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
207 + " Nucleic Acids Research, 22 4673-4680",
208 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
209 "ClustalW Multiple Sequence Alignment"),
212 "Cole C., Barber J. D., Barton G.J (2008) "
213 + "The Jpred 3 secondary structure prediction server "
214 + "Nucleic Acids Research, 36 W197-W201",
215 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
216 "JNet Secondary Structure Prediction") };
217 services = new Hashtable();
218 serviceList = new Vector();
219 buildServiceLists(defServices, serviceList, services);
222 } catch (Exception e)
225 .println("jalview.rootRegistry is not a proper url!\nWas set to "
226 + RootServiceURL + "\n" + e);
231 // TODO: JBPNote : make this discover more services based on list of
232 // discovery service urls, break cyclic references to the same url and
233 // duplicate service entries (same endpoint *and* same interface)
234 private ServiceHandle[] getServices(java.net.URL location)
236 ServiceHandles shs = null;
239 jalview.bin.Cache.log.debug("Discovering services using " + location);
240 shs = locateWebService(location).getServices();
241 } catch (org.apache.axis.AxisFault f)
243 // JBPNote - should do this a better way!
244 if (f.getFaultReason().indexOf("(407)") > -1)
246 if (jalview.gui.Desktop.desktop != null)
250 jalview.gui.Desktop.desktop,
251 "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
252 "Proxy Authorization Failed",
253 JOptionPane.WARNING_MESSAGE);
258 jalview.bin.Cache.log.warn("No Discovery service at " + location);
259 jalview.bin.Cache.log.debug("Axis Fault", f);
261 } catch (Exception e)
263 jalview.bin.Cache.log.warn("No Discovery service at " + location);
264 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
266 if ((shs != null) && shs.getServices().length > 0)
268 return shs.getServices();
274 * Adds a list of services to the service catalog and categorised catalog
275 * returns true if ServiceURLList was modified with a new DiscoveryService URL
285 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
288 boolean seenNewDiscovery = false;
289 for (int i = 0, j = sh.length; i < j; i++)
291 if (!cat.contains(sh[i]))
293 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
294 + " service called " + sh[i].getName() + " exists at "
295 + sh[i].getEndpointURL() + "\n");
296 if (!sscat.containsKey(sh[i].getAbstractName()))
298 sscat.put(sh[i].getAbstractName(), cat = new Vector());
302 cat = (Vector) sscat.get(sh[i].getAbstractName());
305 if (sh[i].getAbstractName().equals("Registry"))
307 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
309 java.net.URL disc_serv = null;
312 disc_serv = new java.net.URL(sh[i].getEndpointURL());
313 if (!ServiceURLList.contains(disc_serv))
315 jalview.bin.Cache.log
316 .debug("Adding new discovery service at "
318 ServiceURLList.add(disc_serv);
319 seenNewDiscovery = true;
321 } catch (Exception e)
323 jalview.bin.Cache.log.debug(
324 "Ignoring bad discovery service URL "
325 + sh[i].getEndpointURL(), e);
331 return seenNewDiscovery;
334 public void discoverServices()
336 Hashtable sscat = new Hashtable();
337 Vector cat = new Vector();
338 ServiceHandle sh[] = null;
340 if (ServiceURLList == null)
342 jalview.bin.Cache.log
343 .debug("No service endpoints to use for service discovery.");
346 while (s_url < ServiceURLList.size())
348 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
351 buildServiceLists(sh, cat, sscat);
355 jalview.bin.Cache.log
356 .warn("No services at "
357 + ((java.net.URL) ServiceURLList.get(s_url))
358 + " - check DISCOVERY_URLS property in .jalview_properties");
362 // TODO: decide on correct semantics for services list - PropertyChange
363 // provides a way of passing the new object around
364 // so no need to access original discovery thread.
365 // Curent decision is to change properties then notify listeners with old
367 Hashtable oldServices = services;
368 // Vector oldServicelist = serviceList;
371 changeSupport.firePropertyChange("services", oldServices, services);
375 * creates a new thread to call discoverServices()
379 final Discoverer discoverer = this;
380 Thread discoverThread = new Thread()
384 discoverer.doDiscovery();
385 discoverer.discoverServices();
388 discoverThread.start();
392 * binding service abstract name to handler class
394 private static Hashtable serviceClientBindings;
396 public static WS1Client getServiceClient(ServiceHandle sh)
398 if (serviceClientBindings == null)
400 // get a list from Config or create below
401 serviceClientBindings = new Hashtable();
402 serviceClientBindings.put("MsaWS", new MsaWSClient());
403 serviceClientBindings.put("SecStrPred", new JPredClient());
404 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
406 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
408 if (instance == null)
411 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
412 + sh.getAbstractName());
416 instance.serviceHandle = sh;
421 * notes on discovery service 1. need to allow multiple discovery source urls.
422 * 2. user interface to add/control list of urls in preferences notes on
423 * wsclient discovery 1. need a classpath property with list of additional
424 * plugin directories 2. optional config to cite specific bindings between
425 * class name and Abstract service name. 3. precedence for automatic discovery
426 * by using getAbstractName for WSClient - user added plugins override default
427 * plugins ? notes on wsclient gui code for gui attachment now moved to
428 * wsclient implementation. Needs more abstraction but approach seems to work.
429 * is it possible to 'generalise' the data retrieval calls further ? current
430 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
431 * new methods for conservation (group or alignment), treecalc (aligned
432 * profile), seqannot (sequences selected from dataset, annotation back to