2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 * <p>Description: </p>
26 * <p>Copyright: Copyright (c) 2004</p>
28 * <p>Company: Dundee University</p>
30 * @author not attributable
34 import java.util.Vector;
35 import java.util.Hashtable;
36 import java.util.StringTokenizer;
37 import javax.swing.JOptionPane;
39 public class Discoverer
40 extends Thread implements Runnable
42 ext.vamsas.IRegistry registry; // the root registry service.
43 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
44 PropertyChangeSupport(this);
47 * change listeners are notified of "services" property changes
49 * @param listener to be added that consumes new services Hashtable object.
51 public void addPropertyChangeListener(
52 java.beans.PropertyChangeListener listener)
54 changeSupport.addPropertyChangeListener(listener);
60 * @param listener to be removed
62 public void removePropertyChangeListener(
63 java.beans.PropertyChangeListener listener)
65 changeSupport.removePropertyChangeListener(listener);
69 * Property change listener firing routine
71 * @param prop services
72 * @param oldvalue old services hash
73 * @param newvalue new services hash
75 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
77 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
81 * Initializes the server field with a valid service implementation.
83 * @return true if service was located.
85 private IRegistry locateWebService(java.net.URL WsURL)
87 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
88 IRegistry server = null;
91 server = loc.getRegistryService(WsURL);
92 ( (RegistryServiceSoapBindingStub) server).setTimeout(60000); // One minute timeout
96 jalview.bin.Cache.log.error(
97 "Serious! Service location failed\nfor URL :" + WsURL +
103 loc.getEngine().setOption("axis", "1");
108 static private java.net.URL RootServiceURL = null;
109 static public Vector ServiceURLList = null;
110 static private boolean reallyDiscoverServices = true;
112 public static java.util.Hashtable services = null; // vectors of services stored by abstractServiceType string
113 public static java.util.Vector serviceList = null; // flat list of services
114 static private Vector getDiscoveryURLS() {
115 Vector urls = new Vector();
116 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
117 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
120 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
121 while (st.hasMoreElements())
126 java.net.URL u = new java.net.URL(url = st.nextToken());
127 if (!urls.contains(u))
130 jalview.bin.Cache.log.info("Ignoring duplicate url in DISCOVERY_URLS list");
134 jalview.bin.Cache.log.warn(
135 "Problem whilst trying to make a URL from '" +
136 ( (url != null) ? url : "<null>")+"'");
137 jalview.bin.Cache.log.warn("This was probably due to a malformed comma separated list"
138 +" in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
139 jalview.bin.Cache.log.debug("Exception was ",ex);
143 {jalview.bin.Cache.log.warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",ex);}
150 * fetch new services or reset to hardwired defaults depending on preferences.
152 static public void doDiscovery()
154 jalview.bin.Cache.log.debug("(Re)-Initialising the discovery URL list.");
157 reallyDiscoverServices = jalview.bin.Cache.getDefault("DISCOVERY_START", false);
158 if (reallyDiscoverServices)
160 ServiceURLList = getDiscoveryURLS();
164 jalview.bin.Cache.log.debug("Setting default services");
165 services = new Hashtable();
166 // Muscle, Clustal and JPred.
167 ServiceHandle[] defServices = {
170 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment " +
171 "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
172 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
173 "Muscle Multiple Protein Sequence Alignment"
177 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "+
178 "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""+
179 " Nucleic Acids Research, 33 511-518",
180 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
181 "MAFFT Multiple Sequence Alignment"),
184 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple" +
185 " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice." +
186 " Nucleic Acids Research, 22 4673-4680",
187 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
188 "ClustalW Multiple Sequence Alignment"),
191 "Cuff J. A and Barton G.J (2000) Application of " +
192 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
193 "Proteins 40:502-511",
194 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred","JNet Secondary Structure Prediction"
196 services = new Hashtable();
197 serviceList = new Vector();
198 buildServiceLists(defServices, serviceList, services);
205 "jalview.rootRegistry is not a proper url!\nWas set to " +
206 RootServiceURL + "\n" + e);
210 // TODO: JBPNote : make this discover more services based on list of
211 // discovery service urls, break cyclic references to the same url and
212 // duplicate service entries (same endpoint *and* same interface)
213 private ServiceHandle[] getServices(java.net.URL location)
215 ServiceHandles shs = null;
218 jalview.bin.Cache.log.debug("Discovering services using " + location);
219 shs = locateWebService(location).getServices();
221 catch (org.apache.axis.AxisFault f) {
222 // JBPNote - should do this a better way!
223 if (f.getFaultReason().indexOf("(407)")>-1) {
224 if (jalview.gui.Desktop.desktop!=null)
225 JOptionPane.showMessageDialog(jalview.gui.Desktop.desktop, "Please set up your proxy settings in the 'Connections' tab of the Preferences window",
226 "Proxy Authorization Failed",
227 JOptionPane.WARNING_MESSAGE);
229 jalview.bin.Cache.log.warn("No Discovery service at " +
231 jalview.bin.Cache.log.debug("Axis Fault", f);
234 catch (Exception e) {
235 jalview.bin.Cache.log.warn("No Discovery service at " +
237 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
239 if ( (shs != null) && shs.getServices().length > 0)
241 return shs.getServices();
247 * Adds a list of services to the service catalog and categorised catalog
248 * returns true if ServiceURLList was modified with a new DiscoveryService URL
249 * @param sh ServiceHandle[]
251 * @param sscat Hashtable
254 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
257 boolean seenNewDiscovery = false;
258 for (int i = 0, j = sh.length; i < j; i++)
260 if (!cat.contains(sh[i]))
262 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName() +
264 sh[i].getName() + " exists at " +
265 sh[i].getEndpointURL() + "\n");
266 if (!sscat.containsKey(sh[i].getAbstractName()))
268 sscat.put(sh[i].getAbstractName(), cat = new Vector());
272 cat = (Vector) sscat.get(sh[i].getAbstractName());
275 if (sh[i].getAbstractName().equals("Registry"))
277 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
279 java.net.URL disc_serv = null;
282 disc_serv = new java.net.URL(sh[i].getEndpointURL());
283 if (!ServiceURLList.contains(disc_serv))
285 jalview.bin.Cache.log.debug(
286 "Adding new discovery service at " + disc_serv);
287 ServiceURLList.add(disc_serv);
288 seenNewDiscovery = true;
293 jalview.bin.Cache.log.debug(
294 "Ignoring bad discovery service URL " + sh[i].getEndpointURL(),
301 return seenNewDiscovery;
304 public void discoverServices()
306 Hashtable sscat = new Hashtable();
307 Vector cat = new Vector();
308 ServiceHandle sh[] = null;
310 if (ServiceURLList==null)
312 jalview.bin.Cache.log.debug("No service endpoints to use for service discovery.");
315 while (s_url < ServiceURLList.size())
317 if ( (sh = getServices( (java.net.URL) ServiceURLList.get(s_url))) != null)
320 buildServiceLists(sh, cat, sscat);
322 jalview.bin.Cache.log.warn(
324 +((java.net.URL) ServiceURLList.get(s_url))
325 +" - check DISCOVERY_URLS property in .jalview_properties");
329 // TODO: decide on correct semantics for services list - PropertyChange
330 // provides a way of passing the new object around
331 // so no need to access original discovery thread.
332 // Curent decision is to change properties then notify listeners with old and new values.
333 Hashtable oldServices = services;
334 //Vector oldServicelist = serviceList;
337 firePropertyChange("services", oldServices, services);
341 * creates a new thread to call discoverServices()
345 final Discoverer discoverer = this;
346 Thread discoverThread = new Thread() {
348 discoverer.doDiscovery();
349 discoverer.discoverServices();
352 discoverThread.start();