2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.jws1;
27 public class Discoverer implements Runnable
29 ext.vamsas.IRegistry registry; // the root registry service.
31 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
35 * change listeners are notified of "services" property changes
38 * to be added that consumes new services Hashtable object.
40 public void addPropertyChangeListener(
41 java.beans.PropertyChangeListener listener)
43 changeSupport.addPropertyChangeListener(listener);
52 public void removePropertyChangeListener(
53 java.beans.PropertyChangeListener listener)
55 changeSupport.removePropertyChangeListener(listener);
59 * Property change listener firing routine
68 public void firePropertyChange(String prop, Object oldvalue,
71 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
75 * Initializes the server field with a valid service implementation.
77 * @return true if service was located.
79 private IRegistry locateWebService(java.net.URL WsURL)
81 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
82 IRegistry server = null;
85 server = loc.getRegistryService(WsURL);
86 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
89 } catch (Exception ex)
92 .error("Serious! Service location failed\nfor URL :" + WsURL
98 loc.getEngine().setOption("axis", "1");
103 static private java.net.URL RootServiceURL = null;
105 static public Vector ServiceURLList = null;
107 static private boolean reallyDiscoverServices = true;
109 public static java.util.Hashtable services = null; // vectors of services
112 // abstractServiceType
115 public static java.util.Vector serviceList = null; // flat list of services
117 static private Vector getDiscoveryURLS()
119 Vector urls = new Vector();
120 String RootServiceURLs = jalview.bin.Cache
121 .getDefault("DISCOVERY_URLS",
122 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
126 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
127 while (st.hasMoreElements())
132 java.net.URL u = new java.net.URL(url = st.nextToken());
133 if (!urls.contains(u))
139 jalview.bin.Cache.log
140 .info("Ignoring duplicate url in DISCOVERY_URLS list");
142 } catch (Exception ex)
144 jalview.bin.Cache.log
145 .warn("Problem whilst trying to make a URL from '"
146 + ((url != null) ? url : "<null>") + "'");
147 jalview.bin.Cache.log
148 .warn("This was probably due to a malformed comma separated list"
149 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
150 jalview.bin.Cache.log.debug("Exception was ", ex);
153 } catch (Exception ex)
155 jalview.bin.Cache.log
156 .warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",
167 * fetch new services or reset to hardwired defaults depending on preferences.
169 static public void doDiscovery()
171 jalview.bin.Cache.log
172 .debug("(Re)-Initialising the discovery URL list.");
175 reallyDiscoverServices = jalview.bin.Cache.getDefault(
176 "DISCOVERY_START", false);
177 if (reallyDiscoverServices)
179 ServiceURLList = getDiscoveryURLS();
183 jalview.bin.Cache.log.debug("Setting default services");
184 services = new Hashtable();
185 // Muscle, Clustal and JPred.
186 ServiceHandle[] defServices =
190 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
191 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
192 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
193 "Muscle Multiple Protein Sequence Alignment"),
196 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
197 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
198 + " Nucleic Acids Research, 33 511-518",
199 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
200 "MAFFT Multiple Sequence Alignment"),
203 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
204 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
205 + " Nucleic Acids Research, 22 4673-4680",
206 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
207 "ClustalW Multiple Sequence Alignment"),
210 "Cole C., Barber J. D., Barton G.J (2008) "
211 + "The Jpred 3 secondary structure prediction server "
212 + "Nucleic Acids Research, 36 W197-W201",
213 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
214 "JNet Secondary Structure Prediction") };
215 services = new Hashtable();
216 serviceList = new Vector();
217 buildServiceLists(defServices, serviceList, services);
220 } catch (Exception e)
223 .println("jalview.rootRegistry is not a proper url!\nWas set to "
224 + RootServiceURL + "\n" + e);
229 // TODO: JBPNote : make this discover more services based on list of
230 // discovery service urls, break cyclic references to the same url and
231 // duplicate service entries (same endpoint *and* same interface)
232 private ServiceHandle[] getServices(java.net.URL location)
234 ServiceHandles shs = null;
237 jalview.bin.Cache.log.debug("Discovering services using " + location);
238 shs = locateWebService(location).getServices();
239 } catch (org.apache.axis.AxisFault f)
241 // JBPNote - should do this a better way!
242 if (f.getFaultReason().indexOf("(407)") > -1)
244 if (jalview.gui.Desktop.desktop != null)
248 jalview.gui.Desktop.desktop,
249 "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
250 "Proxy Authorization Failed",
251 JOptionPane.WARNING_MESSAGE);
256 jalview.bin.Cache.log.warn("No Discovery service at " + location);
257 jalview.bin.Cache.log.debug("Axis Fault", f);
259 } catch (Exception e)
261 jalview.bin.Cache.log.warn("No Discovery service at " + location);
262 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
264 if ((shs != null) && shs.getServices().length > 0)
266 return shs.getServices();
272 * Adds a list of services to the service catalog and categorised catalog
273 * returns true if ServiceURLList was modified with a new DiscoveryService URL
283 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
286 boolean seenNewDiscovery = false;
287 for (int i = 0, j = sh.length; i < j; i++)
289 if (!cat.contains(sh[i]))
291 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
292 + " service called " + sh[i].getName() + " exists at "
293 + sh[i].getEndpointURL() + "\n");
294 if (!sscat.containsKey(sh[i].getAbstractName()))
296 sscat.put(sh[i].getAbstractName(), cat = new Vector());
300 cat = (Vector) sscat.get(sh[i].getAbstractName());
303 if (sh[i].getAbstractName().equals("Registry"))
305 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
307 java.net.URL disc_serv = null;
310 disc_serv = new java.net.URL(sh[i].getEndpointURL());
311 if (!ServiceURLList.contains(disc_serv))
313 jalview.bin.Cache.log
314 .debug("Adding new discovery service at "
316 ServiceURLList.add(disc_serv);
317 seenNewDiscovery = true;
319 } catch (Exception e)
321 jalview.bin.Cache.log.debug(
322 "Ignoring bad discovery service URL "
323 + sh[i].getEndpointURL(), e);
329 return seenNewDiscovery;
332 public void discoverServices()
334 Hashtable sscat = new Hashtable();
335 Vector cat = new Vector();
336 ServiceHandle sh[] = null;
338 if (ServiceURLList == null)
340 jalview.bin.Cache.log
341 .debug("No service endpoints to use for service discovery.");
344 while (s_url < ServiceURLList.size())
346 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
349 buildServiceLists(sh, cat, sscat);
353 jalview.bin.Cache.log
354 .warn("No services at "
355 + ((java.net.URL) ServiceURLList.get(s_url))
356 + " - check DISCOVERY_URLS property in .jalview_properties");
360 // TODO: decide on correct semantics for services list - PropertyChange
361 // provides a way of passing the new object around
362 // so no need to access original discovery thread.
363 // Curent decision is to change properties then notify listeners with old
365 Hashtable oldServices = services;
366 // Vector oldServicelist = serviceList;
369 changeSupport.firePropertyChange("services", oldServices, services);
373 * creates a new thread to call discoverServices()
377 final Discoverer discoverer = this;
378 Thread discoverThread = new Thread()
382 discoverer.doDiscovery();
383 discoverer.discoverServices();
386 discoverThread.start();
390 * binding service abstract name to handler class
392 private static Hashtable serviceClientBindings;
394 public static WS1Client getServiceClient(ServiceHandle sh)
396 if (serviceClientBindings == null)
398 // get a list from Config or create below
399 serviceClientBindings = new Hashtable();
400 serviceClientBindings.put("MsaWS", new MsaWSClient());
401 serviceClientBindings.put("SecStrPred", new JPredClient());
402 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
404 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
406 if (instance == null)
409 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
410 + sh.getAbstractName());
414 instance.serviceHandle = sh;
419 * notes on discovery service 1. need to allow multiple discovery source urls.
420 * 2. user interface to add/control list of urls in preferences notes on
421 * wsclient discovery 1. need a classpath property with list of additional
422 * plugin directories 2. optional config to cite specific bindings between
423 * class name and Abstract service name. 3. precedence for automatic discovery
424 * by using getAbstractName for WSClient - user added plugins override default
425 * plugins ? notes on wsclient gui code for gui attachment now moved to
426 * wsclient implementation. Needs more abstraction but approach seems to work.
427 * is it possible to 'generalise' the data retrieval calls further ? current
428 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
429 * new methods for conservation (group or alignment), treecalc (aligned
430 * profile), seqannot (sequences selected from dataset, annotation back to