2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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;
38 public class Discoverer
39 extends Thread implements Runnable
41 ext.vamsas.IRegistry registry; // the root registry service.
42 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
43 PropertyChangeSupport(this);
46 * change listeners are notified of "services" property changes
48 * @param listener to be added that consumes new services Hashtable object.
50 public void addPropertyChangeListener(
51 java.beans.PropertyChangeListener listener)
53 changeSupport.addPropertyChangeListener(listener);
59 * @param listener to be removed
61 public void removePropertyChangeListener(
62 java.beans.PropertyChangeListener listener)
64 changeSupport.removePropertyChangeListener(listener);
68 * Property change listener firing routine
70 * @param prop services
71 * @param oldvalue old services hash
72 * @param newvalue new services hash
74 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
76 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
80 * Initializes the server field with a valid service implementation.
82 * @return true if service was located.
84 private IRegistry locateWebService(java.net.URL WsURL)
86 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
87 IRegistry server = null;
90 server = loc.getRegistryService(WsURL);
91 ( (RegistryServiceSoapBindingStub) server).setTimeout(60000); // One minute timeout
95 jalview.bin.Cache.log.error(
96 "Serious! Service location failed\nfor URL :" + WsURL +
102 loc.getEngine().setOption("axis", "1");
107 static private java.net.URL RootServiceURL = null;
108 static public Vector ServiceURLList = null;
109 static private boolean reallyDiscoverServices = true;
111 public static java.util.Hashtable services = null; // vectors of services stored by abstractServiceType string
112 public static java.util.Vector serviceList = null; // flat list of services
113 static private Vector getDiscoveryURLS() {
114 Vector urls = new Vector();
115 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
116 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
119 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
120 while (st.hasMoreElements())
125 java.net.URL u = new java.net.URL(url = st.nextToken());
126 if (!urls.contains(u))
129 jalview.bin.Cache.log.info("Ignoring duplicate url in DISCOVERY_URLS list");
133 jalview.bin.Cache.log.warn(
134 "Problem whilst trying to make a URL from '" +
135 ( (url != null) ? url : "<null>")+"'");
136 jalview.bin.Cache.log.warn("This was probably due to a malformed comma separated list"
137 +" in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
138 jalview.bin.Cache.log.debug("Exception was ",ex);
142 {jalview.bin.Cache.log.warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",ex);}
149 * fetch new services or reset to hardwired defaults depending on preferences.
151 static public void doDiscovery()
153 jalview.bin.Cache.log.debug("(Re)-Initialising the discovery URL list.");
156 reallyDiscoverServices = jalview.bin.Cache.getDefault("DISCOVERY_START", false);
157 if (reallyDiscoverServices)
159 ServiceURLList = getDiscoveryURLS();
163 jalview.bin.Cache.log.debug("Setting default services");
164 services = new Hashtable();
165 // Muscle, Clustal and JPred.
166 ServiceHandle[] defServices = {
169 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment " +
170 "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
171 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
172 "Muscle Multiple Protein Sequence Alignment"
176 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple" +
177 " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice." +
178 " Nucleic Acids Research, 22 4673-4680",
179 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
180 "ClustalW Multiple Sequence Alignment"),
183 "Cuff J. A and Barton G.J (2000) Application of " +
184 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
185 "Proteins 40:502-511",
186 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred","JNet Secondary Structure Prediction"
188 services = new Hashtable();
189 serviceList = new Vector();
190 buildServiceLists(defServices, serviceList, services);
197 "jalview.rootRegistry is not a proper url!\nWas set to " +
198 RootServiceURL + "\n" + e);
202 // TODO: JBPNote : make this discover more services based on list of
203 // discovery service urls, break cyclic references to the same url and
204 // duplicate service entries (same endpoint *and* same interface)
205 private ServiceHandle[] getServices(java.net.URL location)
207 ServiceHandles shs = null;
210 jalview.bin.Cache.log.debug("Discovering services using " + location);
211 shs = locateWebService(location).getServices();
215 jalview.bin.Cache.log.debug("No Discovery service at " +
217 jalview.bin.Cache.log.debug(e);
220 if ( (shs != null) && shs.getServices().length > 0)
222 return shs.getServices();
228 * Adds a list of services to the service catalog and categorised catalog
229 * returns true if ServiceURLList was modified with a new DiscoveryService URL
230 * @param sh ServiceHandle[]
232 * @param sscat Hashtable
235 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
238 boolean seenNewDiscovery = false;
239 for (int i = 0, j = sh.length; i < j; i++)
241 if (!cat.contains(sh[i]))
243 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName() +
245 sh[i].getName() + " exists at " +
246 sh[i].getEndpointURL() + "\n");
247 if (!sscat.containsKey(sh[i].getAbstractName()))
249 sscat.put(sh[i].getAbstractName(), cat = new Vector());
253 cat = (Vector) sscat.get(sh[i].getAbstractName());
256 if (sh[i].getAbstractName().equals("Registry"))
258 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
260 java.net.URL disc_serv = null;
263 disc_serv = new java.net.URL(sh[i].getEndpointURL());
264 if (!ServiceURLList.contains(disc_serv))
266 jalview.bin.Cache.log.debug(
267 "Adding new discovery service at " + disc_serv);
268 ServiceURLList.add(disc_serv);
269 seenNewDiscovery = true;
274 jalview.bin.Cache.log.debug(
275 "Ignoring bad discovery service URL " + sh[i].getEndpointURL(),
282 return seenNewDiscovery;
285 public void discoverServices()
287 Hashtable sscat = new Hashtable();
288 Vector cat = new Vector();
289 ServiceHandle sh[] = null;
291 if (ServiceURLList==null)
293 jalview.bin.Cache.log.debug("No service endpoints to use for service discovery.");
296 while (s_url < ServiceURLList.size())
298 if ( (sh = getServices( (java.net.URL) ServiceURLList.get(s_url))) != null)
301 buildServiceLists(sh, cat, sscat);
303 jalview.bin.Cache.log.warn(
305 +((java.net.URL) ServiceURLList.get(s_url))
306 +" - check DISCOVERY_URLS property in .jalview_properties");
310 // TODO: decide on correct semantics for services list - PropertyChange
311 // provides a way of passing the new object around
312 // so no need to access original discovery thread.
313 // Curent decision is to change properties then notify listeners with old and new values.
314 Hashtable oldServices = services;
315 //Vector oldServicelist = serviceList;
318 firePropertyChange("services", oldServices, services);
322 * creates a new thread to call discoverServices()
326 final Discoverer discoverer = this;
327 Thread discoverThread = new Thread() {
329 discoverer.doDiscovery();
330 discoverer.discoverServices();
333 discoverThread.start();