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;
20 public class Discoverer
21 extends Thread implements Runnable
23 ext.vamsas.IRegistry registry; // the root registry service.
24 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
25 PropertyChangeSupport(this);
28 * change listeners are notified of "services" property changes
30 * @param listener to be added that consumes new services Hashtable object.
32 public void addPropertyChangeListener(
33 java.beans.PropertyChangeListener listener)
35 changeSupport.addPropertyChangeListener(listener);
41 * @param listener to be removed
43 public void removePropertyChangeListener(
44 java.beans.PropertyChangeListener listener)
46 changeSupport.removePropertyChangeListener(listener);
50 * Property change listener firing routine
52 * @param prop services
53 * @param oldvalue old services hash
54 * @param newvalue new services hash
56 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
58 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
62 * Initializes the server field with a valid service implementation.
64 * @return true if service was located.
66 private IRegistry locateWebService(java.net.URL WsURL)
68 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
69 IRegistry server = null;
72 server = loc.getRegistryService(WsURL);
73 ( (RegistryServiceSoapBindingStub) server).setTimeout(60000); // One minute timeout
77 jalview.bin.Jalview.log.error(
78 "Serious! Service location failed\nfor URL :" + WsURL +
84 loc.getEngine().setOption("axis", "1");
89 static private java.net.URL RootServiceURL = null;
90 static public Vector ServiceURLList = null;
91 static private boolean reallyDiscoverServices = true;
93 public static java.util.Hashtable services = null; // vectors of services stored by abstractServiceType string
94 public static java.util.Vector serviceList = null; // flat list of services
101 reallyDiscoverServices = jalview.bin.Cache.getDefault("DISCOVERY_START", false);
102 if (reallyDiscoverServices)
104 RootServiceURL = new java.net.URL(
105 "http://webservices.compbio.dundee.ac.uk:8080/jalTestWS/services/ServiceRegistry");
106 if (ServiceURLList == null)
108 ServiceURLList = new Vector();
110 if (!ServiceURLList.contains(RootServiceURL))
112 ServiceURLList.add(RootServiceURL);
117 jalview.bin.Jalview.log.debug("Setting default services");
118 services = new Hashtable();
119 // Muscle, Clustal and JPred.
120 ServiceHandle[] defServices = {
123 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment " +
124 "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
125 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
126 "Muscle Multiple Protein Sequence Alignment"
130 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple" +
131 " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice." +
132 " Nucleic Acids Research, 22 4673-4680",
133 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
134 "ClustalW Multiple Sequence Alignment"),
137 "Cuff J. A and Barton G.J (1999) Application of enhanced " +
138 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
139 "Proteins 40:502-511",
140 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred","JNet Secondary Structure Prediction"
142 services = new Hashtable();
143 serviceList = new Vector();
144 buildServiceLists(defServices, serviceList, services);
151 "jalview.rootRegistry is not a proper url!\nWas set to " +
152 RootServiceURL + "\n" + e);
156 // TODO: JBPNote : make this discover more services based on list of
157 // discovery service urls, break cyclic references to the same url and
158 // duplicate service entries (same endpoint *and* same interface)
159 private ServiceHandle[] getServices(java.net.URL location)
161 ServiceHandles shs = null;
164 jalview.bin.Jalview.log.debug("Discovering services using " + location);
165 shs = locateWebService(location).getServices();
169 System.err.println("failed to locate Services through URL : " +
174 if ( (shs != null) && shs.getServices().length > 0)
176 return shs.getServices();
182 * Adds a list of services to the service catalog and categorised catalog
183 * returns true if ServiceURLList was modified with a new DiscoveryService URL
184 * @param sh ServiceHandle[]
186 * @param sscat Hashtable
189 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
192 boolean seenNewDiscovery = false;
193 for (int i = 0, j = sh.length; i < j; i++)
195 if (!cat.contains(sh[i]))
197 jalview.bin.Jalview.log.debug("A " + sh[i].getAbstractName() +
199 sh[i].getName() + " exists at " +
200 sh[i].getEndpointURL() + "\n");
201 if (!sscat.containsKey(sh[i].getAbstractName()))
203 sscat.put(sh[i].getAbstractName(), cat = new Vector());
207 cat = (Vector) sscat.get(sh[i].getAbstractName());
210 if (sh[i].getAbstractName().equals("Registry"))
212 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
214 java.net.URL disc_serv = null;
217 disc_serv = new java.net.URL(sh[i].getEndpointURL());
218 if (!ServiceURLList.contains(disc_serv))
220 jalview.bin.Jalview.log.debug(
221 "Adding new discovery service at " + disc_serv);
222 ServiceURLList.add(disc_serv);
223 seenNewDiscovery = true;
228 jalview.bin.Jalview.log.debug(
229 "Ignoring bad discovery service URL " + sh[i].getEndpointURL(),
236 return seenNewDiscovery;
239 public void discoverServices()
241 Hashtable sscat = new Hashtable();
242 Vector cat = new Vector();
243 ServiceHandle sh[] = null;
245 if (ServiceURLList==null)
247 jalview.bin.Jalview.log.debug("No service endpoints to use for service discovery.");
250 while (s_url < ServiceURLList.size())
252 if ( (sh = getServices( (java.net.URL) ServiceURLList.get(s_url))) != null)
255 buildServiceLists(sh, cat, sscat);
259 // TODO: decide on correct semantics for services list - PropertyChange
260 // provides a way of passing the new object around
261 // so no need to access original discovery thread.
262 // Curent decision is to change properties then notify listeners with old and new values.
263 Hashtable oldServices = services;
264 Vector oldServicelist = serviceList;
267 firePropertyChange("services", oldServices, services);