2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws1;
26 public class Discoverer implements Runnable
28 ext.vamsas.IRegistry registry; // the root registry service.
30 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
34 * change listeners are notified of "services" property changes
37 * to be added that consumes new services Hashtable object.
39 public void addPropertyChangeListener(
40 java.beans.PropertyChangeListener listener)
42 changeSupport.addPropertyChangeListener(listener);
51 public void removePropertyChangeListener(
52 java.beans.PropertyChangeListener listener)
54 changeSupport.removePropertyChangeListener(listener);
58 * Property change listener firing routine
67 public void firePropertyChange(String prop, Object oldvalue,
70 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
74 * Initializes the server field with a valid service implementation.
76 * @return true if service was located.
78 private IRegistry locateWebService(java.net.URL WsURL)
80 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
81 IRegistry server = null;
84 server = loc.getRegistryService(WsURL);
85 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
88 } catch (Exception ex)
91 .error("Serious! Service location failed\nfor URL :" + WsURL
97 loc.getEngine().setOption("axis", "1");
102 static private java.net.URL RootServiceURL = null;
104 static public Vector ServiceURLList = null;
106 static private boolean reallyDiscoverServices = true;
108 public static java.util.Hashtable services = null; // vectors of services
111 // abstractServiceType
114 public static java.util.Vector serviceList = null; // flat list of services
116 static private Vector getDiscoveryURLS()
118 Vector urls = new Vector();
119 String RootServiceURLs = jalview.bin.Cache
120 .getDefault("DISCOVERY_URLS",
121 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
125 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
126 while (st.hasMoreElements())
131 java.net.URL u = new java.net.URL(url = st.nextToken());
132 if (!urls.contains(u))
138 jalview.bin.Cache.log
139 .info("Ignoring duplicate url in DISCOVERY_URLS list");
141 } catch (Exception ex)
143 jalview.bin.Cache.log
144 .warn("Problem whilst trying to make a URL from '"
145 + ((url != null) ? url : "<null>") + "'");
146 jalview.bin.Cache.log
147 .warn("This was probably due to a malformed comma separated list"
148 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
149 jalview.bin.Cache.log.debug("Exception was ", ex);
152 } catch (Exception ex)
154 jalview.bin.Cache.log
155 .warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",
166 * fetch new services or reset to hardwired defaults depending on preferences.
168 static public void doDiscovery()
170 jalview.bin.Cache.log
171 .debug("(Re)-Initialising the discovery URL list.");
174 reallyDiscoverServices = jalview.bin.Cache.getDefault(
175 "DISCOVERY_START", false);
176 if (reallyDiscoverServices)
178 ServiceURLList = getDiscoveryURLS();
182 jalview.bin.Cache.log.debug("Setting default services");
183 services = new Hashtable();
184 // Muscle, Clustal and JPred.
185 ServiceHandle[] defServices =
189 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
190 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
191 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
192 "Muscle Multiple Protein Sequence Alignment"),
195 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
196 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
197 + " Nucleic Acids Research, 33 511-518",
198 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
199 "MAFFT Multiple Sequence Alignment"),
202 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
203 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
204 + " Nucleic Acids Research, 22 4673-4680",
205 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
206 "ClustalW Multiple Sequence Alignment"),
209 "Cole C., Barber J. D., Barton G.J (2008) "
210 + "The Jpred 3 secondary structure prediction server "
211 + "Nucleic Acids Research, 36 W197-W201",
212 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
213 "JNet Secondary Structure Prediction") };
214 services = new Hashtable();
215 serviceList = new Vector();
216 buildServiceLists(defServices, serviceList, services);
219 } catch (Exception e)
222 .println("jalview.rootRegistry is not a proper url!\nWas set to "
223 + RootServiceURL + "\n" + e);
228 // TODO: JBPNote : make this discover more services based on list of
229 // discovery service urls, break cyclic references to the same url and
230 // duplicate service entries (same endpoint *and* same interface)
231 private ServiceHandle[] getServices(java.net.URL location)
233 ServiceHandles shs = null;
236 jalview.bin.Cache.log.debug("Discovering services using " + location);
237 shs = locateWebService(location).getServices();
238 } catch (org.apache.axis.AxisFault f)
240 // JBPNote - should do this a better way!
241 if (f.getFaultReason().indexOf("(407)") > -1)
243 if (jalview.gui.Desktop.desktop != null)
247 jalview.gui.Desktop.desktop,
248 "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
249 "Proxy Authorization Failed",
250 JOptionPane.WARNING_MESSAGE);
255 jalview.bin.Cache.log.warn("No Discovery service at " + location);
256 jalview.bin.Cache.log.debug("Axis Fault", f);
258 } catch (Exception e)
260 jalview.bin.Cache.log.warn("No Discovery service at " + location);
261 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
263 if ((shs != null) && shs.getServices().length > 0)
265 return shs.getServices();
271 * Adds a list of services to the service catalog and categorised catalog
272 * returns true if ServiceURLList was modified with a new DiscoveryService URL
282 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
285 boolean seenNewDiscovery = false;
286 for (int i = 0, j = sh.length; i < j; i++)
288 if (!cat.contains(sh[i]))
290 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
291 + " service called " + sh[i].getName() + " exists at "
292 + sh[i].getEndpointURL() + "\n");
293 if (!sscat.containsKey(sh[i].getAbstractName()))
295 sscat.put(sh[i].getAbstractName(), cat = new Vector());
299 cat = (Vector) sscat.get(sh[i].getAbstractName());
302 if (sh[i].getAbstractName().equals("Registry"))
304 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
306 java.net.URL disc_serv = null;
309 disc_serv = new java.net.URL(sh[i].getEndpointURL());
310 if (!ServiceURLList.contains(disc_serv))
312 jalview.bin.Cache.log
313 .debug("Adding new discovery service at "
315 ServiceURLList.add(disc_serv);
316 seenNewDiscovery = true;
318 } catch (Exception e)
320 jalview.bin.Cache.log.debug(
321 "Ignoring bad discovery service URL "
322 + sh[i].getEndpointURL(), e);
328 return seenNewDiscovery;
331 public void discoverServices()
333 Hashtable sscat = new Hashtable();
334 Vector cat = new Vector();
335 ServiceHandle sh[] = null;
337 if (ServiceURLList == null)
339 jalview.bin.Cache.log
340 .debug("No service endpoints to use for service discovery.");
343 while (s_url < ServiceURLList.size())
345 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
348 buildServiceLists(sh, cat, sscat);
352 jalview.bin.Cache.log
353 .warn("No services at "
354 + ((java.net.URL) ServiceURLList.get(s_url))
355 + " - check DISCOVERY_URLS property in .jalview_properties");
359 // TODO: decide on correct semantics for services list - PropertyChange
360 // provides a way of passing the new object around
361 // so no need to access original discovery thread.
362 // Curent decision is to change properties then notify listeners with old
364 Hashtable oldServices = services;
365 // Vector oldServicelist = serviceList;
368 changeSupport.firePropertyChange("services", oldServices, services);
372 * creates a new thread to call discoverServices()
376 final Discoverer discoverer = this;
377 Thread discoverThread = new Thread()
381 discoverer.doDiscovery();
382 discoverer.discoverServices();
385 discoverThread.start();
389 * binding service abstract name to handler class
391 private static Hashtable serviceClientBindings;
393 public static WS1Client getServiceClient(ServiceHandle sh)
395 if (serviceClientBindings == null)
397 // get a list from Config or create below
398 serviceClientBindings = new Hashtable();
399 serviceClientBindings.put("MsaWS", new MsaWSClient());
400 serviceClientBindings.put("SecStrPred", new JPredClient());
401 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
403 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
405 if (instance == null)
408 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
409 + sh.getAbstractName());
413 instance.serviceHandle = sh;
418 * notes on discovery service 1. need to allow multiple discovery source urls.
419 * 2. user interface to add/control list of urls in preferences notes on
420 * wsclient discovery 1. need a classpath property with list of additional
421 * plugin directories 2. optional config to cite specific bindings between
422 * class name and Abstract service name. 3. precedence for automatic discovery
423 * by using getAbstractName for WSClient - user added plugins override default
424 * plugins ? notes on wsclient gui code for gui attachment now moved to
425 * wsclient implementation. Needs more abstraction but approach seems to work.
426 * is it possible to 'generalise' the data retrieval calls further ? current
427 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
428 * new methods for conservation (group or alignment), treecalc (aligned
429 * profile), seqannot (sequences selected from dataset, annotation back to