import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
DropTargetListener, ClipboardOwner, IProgressIndicator
{
- private class JalviewChangeSupport implements PropertyChangeListener
- {
- public void propertyChange(PropertyChangeEvent evt)
- {
- // Handle change events - most are simply routed to other sources
- changeSupport.firePropertyChange(evt);
- }
-
- /**
- * change listeners are notified of changes to resources so they can update
- * their state. E.g. - the 'services' property notifies when the available
- * set of web service endpoints have changed.
- */
- private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
- this);
-
- /**
- * @param propertyName
- * @param listener
- * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.lang.String,
- * java.beans.PropertyChangeListener)
- */
- public void addJalviewPropertyChangeListener(String propertyName,
- PropertyChangeListener listener)
- {
- changeSupport.addPropertyChangeListener(propertyName, listener);
- }
-
- /**
- * @param listener
- * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
- */
- public void addJalviewPropertyChangeListener(
- PropertyChangeListener listener)
- {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- /*
- * @param propertyName
- *
- * @param oldValue
- *
- * @param newValue
- *
- * @see
- * java.beans.PropertyChangeSupport#firePropertyChange(java.lang.String,
- * java.lang.Object, java.lang.Object) public void firePropertyChange(String
- * propertyName, Object oldValue, Object newValue) {
- * changeSupport.firePropertyChange(propertyName, oldValue, newValue); }
- */
-
- /**
- * @param propertyName
- * @param listener
- * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.lang.String,
- * java.beans.PropertyChangeListener)
- */
- public void removeJalviewPropertyChangeListener(String propertyName,
- PropertyChangeListener listener)
- {
- changeSupport.removePropertyChangeListener(propertyName, listener);
- }
-
- }
-
private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
/**
* @param listener
- * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
+ * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
*/
public void addJalviewPropertyChangeListener(
PropertyChangeListener listener)
/**
* @param propertyName
* @param listener
- * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
+ * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
* java.beans.PropertyChangeListener)
*/
public void addJalviewPropertyChangeListener(String propertyName,
/**
* @param propertyName
* @param listener
- * @see jalview.gui.Desktop.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
+ * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
* java.beans.PropertyChangeListener)
*/
public void removeJalviewPropertyChangeListener(String propertyName,
}
if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
{
- jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
- .addPropertyChangeListener(changeSupport);
- (t2 = new Thread(jalview.ws.jws2.Jws2Discoverer.getDiscoverer()))
- .start();
+ if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning()) {
+ jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
+ }
+ t2=jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(changeSupport);
+
}
if (blocking)
{
--- /dev/null
+package jalview.gui;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+public class JalviewChangeSupport implements PropertyChangeListener
+{
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // Handle change events - most are simply routed to other sources
+ changeSupport.firePropertyChange(evt);
+ }
+
+ /**
+ * change listeners are notified of changes to resources so they can update
+ * their state. E.g. - the 'services' property notifies when the available
+ * set of web service endpoints have changed.
+ */
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
+ this);
+
+ /**
+ * @param propertyName
+ * @param listener
+ * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.lang.String,
+ * java.beans.PropertyChangeListener)
+ */
+ public void addJalviewPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(propertyName, listener);
+ }
+
+ /**
+ * @param listener
+ * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ public void addJalviewPropertyChangeListener(
+ PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /*
+ * @param propertyName
+ *
+ * @param oldValue
+ *
+ * @param newValue
+ *
+ * @see
+ * java.beans.PropertyChangeSupport#firePropertyChange(java.lang.String,
+ * java.lang.Object, java.lang.Object) public void firePropertyChange(String
+ * propertyName, Object oldValue, Object newValue) {
+ * changeSupport.firePropertyChange(propertyName, oldValue, newValue); }
+ */
+
+ /**
+ * @param propertyName
+ * @param listener
+ * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.lang.String,
+ * java.beans.PropertyChangeListener)
+ */
+ public void removeJalviewPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(propertyName, listener);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ *
+ */
+package jalview.ws.jws2;
+
+import jalview.bin.Cache;
+
+import compbio.data.msa.MsaWS;
+import compbio.ws.client.Jws2Client;
+import compbio.ws.client.Services;
+
+/**
+ * @author JimP
+ *
+ */
+public class JabaWsServerQuery implements Runnable
+{
+
+ Jws2Discoverer jws2Discoverer=null;
+ String jwsservers=null;
+ boolean quit=false,
+ running=false;
+ /**
+ * @return the running
+ */
+ public boolean isRunning()
+ {
+ return running;
+ }
+
+ /**
+ * @param quit the quit to set
+ */
+ public void setQuit(boolean quit)
+ {
+ this.quit = quit;
+ }
+
+ public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
+ {
+ this.jws2Discoverer = jws2Discoverer;
+ this.jwsservers=jwsservers;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run()
+ {
+ running=true;
+ try
+ {
+ if (Jws2Client.validURL(jwsservers))
+ {
+ // look for services
+ for (Services srv : Services.values())
+ {
+ if (quit)
+ {
+ running=false;
+ return;
+ }
+ 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)
+ {
+ jws2Discoverer.addService(jwsservers, srv, service);
+ }
+ }
+
+ }
+ else
+ {
+ Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Cache.log.warn("Exception when discovering Jws2 services.", e);
+ } catch (Error e)
+ {
+ Cache.log.error("Exception when discovering Jws2 services.", e);
+ }
+ running=false;
+ }
+
+}
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;
+ }
+
}