import java.io.Closeable;
import java.net.ConnectException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
import jalview.datamodel.AlignmentView;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
+import jalview.gui.JalviewChangeSupport;
import jalview.ws.WSMenuEntryProviderI;
import jalview.ws.params.ParamDatastoreI;
import compbio.data.msa.MsaWS;
changeSupport.removePropertyChangeListener(listener);
}
- boolean running = false;
+ boolean running = false, aborted = false;
+
+ /**
+ * @param aborted
+ * the aborted to set
+ */
+ public void setAborted(boolean aborted)
+ {
+ this.aborted = aborted;
+ }
Thread oldthread = null;
{
if (running && oldthread != null && oldthread.isAlive())
{
- return;
+ if (!aborted)
+ {
+ return;
+ }
+ while (running)
+ {
+ try
+ {
+ Cache.log
+ .debug("Waiting around for old discovery thread to finish.");
+ // wait around until old discoverer dies
+ Thread.sleep(100);
+ } catch (Exception e)
+ {
+ }
+ }
+ Cache.log.debug("Old discovery thread has finished.");
}
running = true;
oldthread = Thread.currentThread();
{
services.removeAllElements();
}
- for (String jwsservers : getServiceUrls())
+ List<JabaWsServerQuery> qrys = new ArrayList<JabaWsServerQuery>();
+ for (final String jwsservers : getServiceUrls())
+ {
+ JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsservers);
+ qrys.add(squery);
+ new Thread(squery).start();
+ }
+ boolean finished = false;
+ do
{
try
{
- if (Jws2Client.validURL(jwsservers))
- {
- // look for services
- for (Services srv : Services.values())
- {
- MsaWS service = null;
- try
- {
- service = Jws2Client.connect(jwsservers, srv);
- } catch (Exception e)
- {
- System.err.println("Jws2 Discoverer: Problem on "
- + jwsservers + " with service " + srv + ":\n"
- + e.getMessage());
- if (!(e instanceof javax.xml.ws.WebServiceException))
- {
- e.printStackTrace();
- }
- }
- ;
- if (service != null)
- {
- addService(jwsservers, srv, service);
- }
- }
-
- }
- else
- {
- Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
- }
+ Thread.sleep(100);
} catch (Exception e)
{
- e.printStackTrace();
- Cache.log.warn("Exception when discovering Jws2 services.", e);
- } catch (Error e)
+ }
+ ;
+ for (JabaWsServerQuery squery : qrys)
+ {
+ finished |= !squery.isRunning();
+ }
+ if (aborted)
{
- Cache.log.error("Exception when discovering Jws2 services.", e);
+ Cache.log.debug("Aborting " + qrys.size()
+ + " JABAWS discovery threads.");
+ for (JabaWsServerQuery squery : qrys)
+ {
+ squery.setQuit(true);
+ }
}
- }
+ } while (!aborted && !finished);
oldthread = null;
running = false;
- changeSupport.firePropertyChange("services", new Vector(), services);
+ if (!aborted)
+ {
+ changeSupport.firePropertyChange("services", new Vector(), services);
+ }
}
/**
* @param srv
* @param service2
*/
- private void addService(String jwsservers, Services srv, MsaWS service2)
+ synchronized void addService(String jwsservers, Services srv,
+ MsaWS service2)
{
if (services == null)
{
public static void main(String[] args)
{
- Thread runner = new Thread(getDiscoverer());
- getDiscoverer().addPropertyChangeListener(new PropertyChangeListener()
+ Thread runner = getDiscoverer().startDiscoverer(new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent evt)
{
- System.out.println("Changesupport: There are now "
+ if (getDiscoverer().services!=null)
+ {System.out.println("Changesupport: There are now "
+ getDiscoverer().services.size() + " services");
+
+ }
}
});
- runner.start();
while (runner.isAlive())
{
try
return true;
}
+ /**
+ * Start a fresh discovery thread and notify the given object when we're finished. Any known existing threads will be killed before this one is started.
+ * @param changeSupport2
+ * @return new thread
+ */
+ public Thread startDiscoverer(PropertyChangeListener changeSupport2)
+ {
+ if (isRunning())
+ {
+ setAborted(true);
+ }
+ addPropertyChangeListener(changeSupport2);
+ Thread thr = new Thread(this);
+ thr.start();
+ return thr;
+ }
+
}