2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
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 implements Runnable
49 ext.vamsas.IRegistry registry; // the root registry service.
51 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
54 * change listeners are notified of "services" property changes
57 * to be added that consumes new services Hashtable object.
59 public void addPropertyChangeListener(
60 java.beans.PropertyChangeListener listener)
62 changeSupport.addPropertyChangeListener(listener);
71 public void removePropertyChangeListener(
72 java.beans.PropertyChangeListener listener)
74 changeSupport.removePropertyChangeListener(listener);
78 * Property change listener firing routine
87 public void firePropertyChange(String prop, Object oldvalue,
90 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
94 * Initializes the server field with a valid service implementation.
96 * @return true if service was located.
98 private IRegistry locateWebService(java.net.URL WsURL)
100 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
101 IRegistry server = null;
104 server = loc.getRegistryService(WsURL);
105 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
108 } catch (Exception ex)
110 jalview.bin.Cache.log
111 .error("Serious! Service location failed\nfor URL :" + WsURL
117 loc.getEngine().setOption("axis", "1");
122 static private java.net.URL RootServiceURL = null;
124 static public Vector ServiceURLList = null;
126 static private boolean reallyDiscoverServices = true;
128 public static java.util.Hashtable services = null; // vectors of services
131 // abstractServiceType
134 public static java.util.Vector serviceList = null; // flat list of services
136 static private Vector getDiscoveryURLS()
138 Vector urls = new Vector();
139 String RootServiceURLs = jalview.bin.Cache
140 .getDefault("DISCOVERY_URLS",
141 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
145 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
146 while (st.hasMoreElements())
151 java.net.URL u = new java.net.URL(url = st.nextToken());
152 if (!urls.contains(u))
158 jalview.bin.Cache.log
159 .info("Ignoring duplicate url in DISCOVERY_URLS list");
161 } catch (Exception ex)
163 jalview.bin.Cache.log
164 .warn("Problem whilst trying to make a URL from '"
165 + ((url != null) ? url : "<null>") + "'");
166 jalview.bin.Cache.log
167 .warn("This was probably due to a malformed comma separated list"
168 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
169 jalview.bin.Cache.log.debug("Exception was ", ex);
172 } catch (Exception ex)
174 jalview.bin.Cache.log
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.");
195 reallyDiscoverServices = jalview.bin.Cache.getDefault(
196 "DISCOVERY_START", false);
197 if (reallyDiscoverServices)
199 ServiceURLList = getDiscoveryURLS();
203 jalview.bin.Cache.log.debug("Setting default services");
204 services = new Hashtable();
205 // Muscle, Clustal and JPred.
206 ServiceHandle[] defServices =
210 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
211 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
212 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
213 "Muscle Multiple Protein Sequence Alignment"),
216 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
217 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
218 + " Nucleic Acids Research, 33 511-518",
219 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
220 "MAFFT Multiple Sequence Alignment"),
223 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
224 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
225 + " Nucleic Acids Research, 22 4673-4680",
226 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
227 "ClustalW Multiple Sequence Alignment"),
230 "Cole C., Barber J. D., Barton G.J (2008) "
231 + "The Jpred 3 secondary structure prediction server "
232 + "Nucleic Acids Research, 36 W197-W201",
233 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
234 "JNet Secondary Structure Prediction") };
235 services = new Hashtable();
236 serviceList = new Vector();
237 buildServiceLists(defServices, serviceList, services);
240 } catch (Exception e)
243 .println("jalview.rootRegistry is not a proper url!\nWas set to "
244 + RootServiceURL + "\n" + e);
249 // TODO: JBPNote : make this discover more services based on list of
250 // discovery service urls, break cyclic references to the same url and
251 // duplicate service entries (same endpoint *and* same interface)
252 private ServiceHandle[] getServices(java.net.URL location)
254 ServiceHandles shs = null;
257 jalview.bin.Cache.log.debug("Discovering services using " + location);
258 shs = locateWebService(location).getServices();
259 } catch (org.apache.axis.AxisFault f)
261 // JBPNote - should do this a better way!
262 if (f.getFaultReason().indexOf("(407)") > -1)
264 if (jalview.gui.Desktop.desktop != null)
268 jalview.gui.Desktop.desktop,
269 "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
270 "Proxy Authorization Failed",
271 JOptionPane.WARNING_MESSAGE);
276 jalview.bin.Cache.log.warn("No Discovery service at " + location);
277 jalview.bin.Cache.log.debug("Axis Fault", f);
279 } catch (Exception e)
281 jalview.bin.Cache.log.warn("No Discovery service at " + location);
282 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
284 if ((shs != null) && shs.getServices().length > 0)
286 return shs.getServices();
292 * Adds a list of services to the service catalog and categorised catalog
293 * returns true if ServiceURLList was modified with a new DiscoveryService URL
303 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
306 boolean seenNewDiscovery = false;
307 for (int i = 0, j = sh.length; i < j; i++)
309 if (!cat.contains(sh[i]))
311 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
312 + " service called " + sh[i].getName() + " exists at "
313 + sh[i].getEndpointURL() + "\n");
314 if (!sscat.containsKey(sh[i].getAbstractName()))
316 sscat.put(sh[i].getAbstractName(), cat = new Vector());
320 cat = (Vector) sscat.get(sh[i].getAbstractName());
323 if (sh[i].getAbstractName().equals("Registry"))
325 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
327 java.net.URL disc_serv = null;
330 disc_serv = new java.net.URL(sh[i].getEndpointURL());
331 if (!ServiceURLList.contains(disc_serv))
333 jalview.bin.Cache.log
334 .debug("Adding new discovery service at "
336 ServiceURLList.add(disc_serv);
337 seenNewDiscovery = true;
339 } catch (Exception e)
341 jalview.bin.Cache.log.debug(
342 "Ignoring bad discovery service URL "
343 + sh[i].getEndpointURL(), e);
349 return seenNewDiscovery;
352 public void discoverServices()
354 Hashtable sscat = new Hashtable();
355 Vector cat = new Vector();
356 ServiceHandle sh[] = null;
358 if (ServiceURLList == null)
360 jalview.bin.Cache.log
361 .debug("No service endpoints to use for service discovery.");
364 while (s_url < ServiceURLList.size())
366 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
369 buildServiceLists(sh, cat, sscat);
373 jalview.bin.Cache.log
374 .warn("No services at "
375 + ((java.net.URL) ServiceURLList.get(s_url))
376 + " - check DISCOVERY_URLS property in .jalview_properties");
380 // TODO: decide on correct semantics for services list - PropertyChange
381 // provides a way of passing the new object around
382 // so no need to access original discovery thread.
383 // Curent decision is to change properties then notify listeners with old
385 Hashtable oldServices = services;
386 // Vector oldServicelist = serviceList;
389 changeSupport.firePropertyChange("services", oldServices, services);
393 * creates a new thread to call discoverServices()
397 final Discoverer discoverer = this;
398 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 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 = (WS1Client) serviceClientBindings.get(sh
426 if (instance == null)
429 .println("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