8 * <p>Copyright: Copyright (c) 2004</p>
10 * <p>Company: Dundee University</p>
12 * @author not attributable
16 import java.util.Vector;
17 import java.util.Hashtable;
18 import java.util.ArrayList;
19 import java.util.StringTokenizer;
21 public class Discoverer
22 extends Thread implements Runnable
24 ext.vamsas.IRegistry registry; // the root registry service.
25 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
26 PropertyChangeSupport(this);
29 * change listeners are notified of "services" property changes
31 * @param listener to be added that consumes new services Hashtable object.
33 public void addPropertyChangeListener(
34 java.beans.PropertyChangeListener listener)
36 changeSupport.addPropertyChangeListener(listener);
42 * @param listener to be removed
44 public void removePropertyChangeListener(
45 java.beans.PropertyChangeListener listener)
47 changeSupport.removePropertyChangeListener(listener);
51 * Property change listener firing routine
53 * @param prop services
54 * @param oldvalue old services hash
55 * @param newvalue new services hash
57 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
59 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
63 * Initializes the server field with a valid service implementation.
65 * @return true if service was located.
67 private IRegistry locateWebService(java.net.URL WsURL)
69 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
70 IRegistry server = null;
73 server = loc.getRegistryService(WsURL);
74 ( (RegistryServiceSoapBindingStub) server).setTimeout(60000); // One minute timeout
78 jalview.bin.Jalview.log.error(
79 "Serious! Service location failed\nfor URL :" + WsURL +
85 loc.getEngine().setOption("axis", "1");
90 static private java.net.URL RootServiceURL = null;
91 static public Vector ServiceURLList = null;
92 static private boolean reallyDiscoverServices = true;
94 public static java.util.Hashtable services = null; // vectors of services stored by abstractServiceType string
95 public static java.util.Vector serviceList = null; // flat list of services
96 static private Vector getDiscoveryURLS() {
97 Vector urls = new Vector();
98 String RootServiceURLs = jalview.bin.Cache.getDefault("DISCOVERY_URLS",
99 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
102 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
103 while (st.hasMoreElements())
108 java.net.URL u = new java.net.URL(url = st.nextToken());
109 if (!urls.contains(u))
112 jalview.bin.Jalview.log.info("Ignoring duplicate url in DISCOVERY_URLS list");
116 jalview.bin.Jalview.log.warn(
117 "Problem whilst trying to make a URL from '" +
118 ( (url != null) ? url : "<null>")+"'");
119 jalview.bin.Jalview.log.warn("This was probably due to a malformed comma separated list"
120 +" in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
121 jalview.bin.Jalview.log.debug("Exception was ",ex);
125 {jalview.bin.Jalview.log.warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",ex);}
135 reallyDiscoverServices = jalview.bin.Cache.getDefault("DISCOVERY_START", false);
136 if (reallyDiscoverServices)
138 ServiceURLList = getDiscoveryURLS();
142 jalview.bin.Jalview.log.debug("Setting default services");
143 services = new Hashtable();
144 // Muscle, Clustal and JPred.
145 ServiceHandle[] defServices = {
148 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment " +
149 "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
150 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
151 "Muscle Multiple Protein Sequence Alignment"
155 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple" +
156 " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice." +
157 " Nucleic Acids Research, 22 4673-4680",
158 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
159 "ClustalW Multiple Sequence Alignment"),
162 "Cuff J. A and Barton G.J (1999) Application of enhanced " +
163 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
164 "Proteins 40:502-511",
165 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred","JNet Secondary Structure Prediction"
167 services = new Hashtable();
168 serviceList = new Vector();
169 buildServiceLists(defServices, serviceList, services);
176 "jalview.rootRegistry is not a proper url!\nWas set to " +
177 RootServiceURL + "\n" + e);
181 // TODO: JBPNote : make this discover more services based on list of
182 // discovery service urls, break cyclic references to the same url and
183 // duplicate service entries (same endpoint *and* same interface)
184 private ServiceHandle[] getServices(java.net.URL location)
186 ServiceHandles shs = null;
189 jalview.bin.Jalview.log.debug("Discovering services using " + location);
190 shs = locateWebService(location).getServices();
194 jalview.bin.Jalview.log.debug("No Discovery service at " +
196 jalview.bin.Jalview.log.debug(e);
199 if ( (shs != null) && shs.getServices().length > 0)
201 return shs.getServices();
207 * Adds a list of services to the service catalog and categorised catalog
208 * returns true if ServiceURLList was modified with a new DiscoveryService URL
209 * @param sh ServiceHandle[]
211 * @param sscat Hashtable
214 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
217 boolean seenNewDiscovery = false;
218 for (int i = 0, j = sh.length; i < j; i++)
220 if (!cat.contains(sh[i]))
222 jalview.bin.Jalview.log.debug("A " + sh[i].getAbstractName() +
224 sh[i].getName() + " exists at " +
225 sh[i].getEndpointURL() + "\n");
226 if (!sscat.containsKey(sh[i].getAbstractName()))
228 sscat.put(sh[i].getAbstractName(), cat = new Vector());
232 cat = (Vector) sscat.get(sh[i].getAbstractName());
235 if (sh[i].getAbstractName().equals("Registry"))
237 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
239 java.net.URL disc_serv = null;
242 disc_serv = new java.net.URL(sh[i].getEndpointURL());
243 if (!ServiceURLList.contains(disc_serv))
245 jalview.bin.Jalview.log.debug(
246 "Adding new discovery service at " + disc_serv);
247 ServiceURLList.add(disc_serv);
248 seenNewDiscovery = true;
253 jalview.bin.Jalview.log.debug(
254 "Ignoring bad discovery service URL " + sh[i].getEndpointURL(),
261 return seenNewDiscovery;
264 public void discoverServices()
266 Hashtable sscat = new Hashtable();
267 Vector cat = new Vector();
268 ServiceHandle sh[] = null;
270 if (ServiceURLList==null)
272 jalview.bin.Jalview.log.debug("No service endpoints to use for service discovery.");
275 while (s_url < ServiceURLList.size())
277 if ( (sh = getServices( (java.net.URL) ServiceURLList.get(s_url))) != null)
280 buildServiceLists(sh, cat, sscat);
282 jalview.bin.Jalview.log.warn(
284 +((java.net.URL) ServiceURLList.get(s_url))
285 +" - check DISCOVERY_URLS property in .jalview_properties");
289 // TODO: decide on correct semantics for services list - PropertyChange
290 // provides a way of passing the new object around
291 // so no need to access original discovery thread.
292 // Curent decision is to change properties then notify listeners with old and new values.
293 Hashtable oldServices = services;
294 Vector oldServicelist = serviceList;
297 firePropertyChange("services", oldServices, services);