2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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;
30 * Copyright: Copyright (c) 2004
34 * Company: Dundee University
37 * @author not attributable
47 public class Discoverer extends Thread implements Runnable
49 ext.vamsas.IRegistry registry; // the root registry service.
51 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
55 * change listeners are notified of "services" property changes
58 * to be added that consumes new services Hashtable object.
60 public void addPropertyChangeListener(
61 java.beans.PropertyChangeListener listener)
63 changeSupport.addPropertyChangeListener(listener);
72 public void removePropertyChangeListener(
73 java.beans.PropertyChangeListener listener)
75 changeSupport.removePropertyChangeListener(listener);
79 * Property change listener firing routine
88 public void firePropertyChange(String prop, Object oldvalue,
91 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
95 * Initializes the server field with a valid service implementation.
97 * @return true if service was located.
99 private IRegistry locateWebService(java.net.URL WsURL)
101 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
102 IRegistry server = null;
105 server = loc.getRegistryService(WsURL);
106 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
109 } catch (Exception ex)
111 jalview.bin.Cache.log
112 .error("Serious! Service location failed\nfor URL :" + WsURL
118 loc.getEngine().setOption("axis", "1");
123 static private java.net.URL RootServiceURL = null;
125 static public Vector ServiceURLList = null;
127 static private boolean reallyDiscoverServices = true;
129 public static java.util.Hashtable services = null; // vectors of services
132 // abstractServiceType
135 public static java.util.Vector serviceList = null; // flat list of services
137 static private Vector getDiscoveryURLS()
139 Vector urls = new Vector();
140 String RootServiceURLs = jalview.bin.Cache
141 .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
168 .warn("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
177 "Error parsing comma separated list of urls in DISCOVERY_URLS.",
188 * fetch new services or reset to hardwired defaults depending on preferences.
190 static public void doDiscovery()
192 jalview.bin.Cache.log
193 .debug("(Re)-Initialising the discovery URL list.");
196 reallyDiscoverServices = jalview.bin.Cache.getDefault(
197 "DISCOVERY_START", false);
198 if (reallyDiscoverServices)
200 ServiceURLList = getDiscoveryURLS();
204 jalview.bin.Cache.log.debug("Setting default services");
205 services = new Hashtable();
206 // Muscle, Clustal and JPred.
207 ServiceHandle[] defServices =
211 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
212 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
213 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
214 "Muscle Multiple Protein Sequence Alignment"),
217 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
218 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
219 + " Nucleic Acids Research, 33 511-518",
220 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
221 "MAFFT Multiple Sequence Alignment"),
224 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
225 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
226 + " Nucleic Acids Research, 22 4673-4680",
227 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
228 "ClustalW Multiple Sequence Alignment"),
231 "Cole C., Barber J. D., Barton G.J (2008) "
232 + "The Jpred 3 secondary structure prediction server "
233 + "Nucleic Acids Research, 36 W197-W201",
234 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
235 "JNet Secondary Structure Prediction") };
236 services = new Hashtable();
237 serviceList = new Vector();
238 buildServiceLists(defServices, serviceList, services);
241 } catch (Exception e)
244 .println("jalview.rootRegistry is not a proper url!\nWas set to "
245 + RootServiceURL + "\n" + e);
250 // TODO: JBPNote : make this discover more services based on list of
251 // discovery service urls, break cyclic references to the same url and
252 // duplicate service entries (same endpoint *and* same interface)
253 private ServiceHandle[] getServices(java.net.URL location)
255 ServiceHandles shs = null;
258 jalview.bin.Cache.log.debug("Discovering services using " + location);
259 shs = locateWebService(location).getServices();
260 } catch (org.apache.axis.AxisFault f)
262 // JBPNote - should do this a better way!
263 if (f.getFaultReason().indexOf("(407)") > -1)
265 if (jalview.gui.Desktop.desktop != null)
269 jalview.gui.Desktop.desktop,
270 "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
271 "Proxy Authorization Failed",
272 JOptionPane.WARNING_MESSAGE);
277 jalview.bin.Cache.log.warn("No Discovery service at " + location);
278 jalview.bin.Cache.log.debug("Axis Fault", f);
280 } catch (Exception e)
282 jalview.bin.Cache.log.warn("No Discovery service at " + location);
283 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
285 if ((shs != null) && shs.getServices().length > 0)
287 return shs.getServices();
293 * Adds a list of services to the service catalog and categorised catalog
294 * returns true if ServiceURLList was modified with a new DiscoveryService URL
304 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
307 boolean seenNewDiscovery = false;
308 for (int i = 0, j = sh.length; i < j; i++)
310 if (!cat.contains(sh[i]))
312 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
313 + " service called " + sh[i].getName() + " exists at "
314 + sh[i].getEndpointURL() + "\n");
315 if (!sscat.containsKey(sh[i].getAbstractName()))
317 sscat.put(sh[i].getAbstractName(), cat = new Vector());
321 cat = (Vector) sscat.get(sh[i].getAbstractName());
324 if (sh[i].getAbstractName().equals("Registry"))
326 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
328 java.net.URL disc_serv = null;
331 disc_serv = new java.net.URL(sh[i].getEndpointURL());
332 if (!ServiceURLList.contains(disc_serv))
334 jalview.bin.Cache.log
335 .debug("Adding new discovery service at "
337 ServiceURLList.add(disc_serv);
338 seenNewDiscovery = true;
340 } catch (Exception e)
342 jalview.bin.Cache.log.debug(
343 "Ignoring bad discovery service URL "
344 + sh[i].getEndpointURL(), e);
350 return seenNewDiscovery;
353 public void discoverServices()
355 Hashtable sscat = new Hashtable();
356 Vector cat = new Vector();
357 ServiceHandle sh[] = null;
359 if (ServiceURLList == null)
361 jalview.bin.Cache.log
362 .debug("No service endpoints to use for service discovery.");
365 while (s_url < ServiceURLList.size())
367 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
370 buildServiceLists(sh, cat, sscat);
374 jalview.bin.Cache.log
375 .warn("No services at "
376 + ((java.net.URL) ServiceURLList.get(s_url))
377 + " - check DISCOVERY_URLS property in .jalview_properties");
381 // TODO: decide on correct semantics for services list - PropertyChange
382 // provides a way of passing the new object around
383 // so no need to access original discovery thread.
384 // Curent decision is to change properties then notify listeners with old
386 Hashtable oldServices = services;
387 // Vector oldServicelist = serviceList;
390 firePropertyChange("services", oldServices, services);
394 * creates a new thread to call discoverServices()
398 final Discoverer discoverer = this;
399 Thread discoverThread = new Thread()
403 discoverer.doDiscovery();
404 discoverer.discoverServices();
407 discoverThread.start();
411 * binding service abstract name to handler class
413 private static Hashtable serviceClientBindings;
415 public static WS1Client getServiceClient(ServiceHandle sh)
417 if (serviceClientBindings == null)
419 // get a list from Config or create below
420 serviceClientBindings = new Hashtable();
421 serviceClientBindings.put("MsaWS", new MsaWSClient());
422 serviceClientBindings.put("SecStrPred", new JPredClient());
423 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
425 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
427 if (instance == null)
430 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
431 + sh.getAbstractName());
435 instance.serviceHandle = sh;
440 * notes on discovery service 1. need to allow multiple discovery source urls.
441 * 2. user interface to add/control list of urls in preferences notes on
442 * wsclient discovery 1. need a classpath property with list of additional
443 * plugin directories 2. optional config to cite specific bindings between
444 * class name and Abstract service name. 3. precedence for automatic discovery
445 * by using getAbstractName for WSClient - user added plugins override default
446 * plugins ? notes on wsclient gui code for gui attachment now moved to
447 * wsclient implementation. Needs more abstraction but approach seems to work.
448 * is it possible to 'generalise' the data retrieval calls further ? current
449 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
450 * new methods for conservation (group or alignment), treecalc (aligned
451 * profile), seqannot (sequences selected from dataset, annotation back to