From 846cdbd9bc4b60826bc5429a117e72fc29347a30 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 17 May 2010 16:13:06 +0000 Subject: [PATCH] more robust jws2 service discovery --- src/jalview/gui/AlignFrame.java | 202 +++++++++++++++++++++---------- src/jalview/gui/Desktop.java | 4 +- src/jalview/ws/jws2/Jws2Discoverer.java | 49 +++++++- 3 files changed, 180 insertions(+), 75 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a6caa51..18465e1 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -36,6 +36,7 @@ import jalview.io.*; import jalview.jbgui.*; import jalview.schemes.*; import jalview.ws.*; +import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; /** @@ -513,7 +514,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* Set up intrinsic listeners for dynamically generated GUI bits. */ private void addServiceListeners() { - final java.beans.PropertyChangeListener thisListener; + final java.beans.PropertyChangeListener thisListener, thatListener; // Do this once to get current state BuildWebServiceMenu(); Desktop.discoverer @@ -524,12 +525,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // System.out.println("Discoverer property change."); if (evt.getPropertyName().equals("services")) { - // System.out.println("Rebuilding web service menu"); - BuildWebServiceMenu(); + SwingUtilities.invokeLater(new Runnable() + { + + @Override + public void run() + { + System.err.println("Change support: build services again."); + BuildWebServiceMenu(); + } + + }); } } }); - + jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + .addPropertyChangeListener( + thatListener = new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + SwingUtilities.invokeLater(new Runnable() + { + + @Override + public void run() + { + System.err.println("Change support: build services again."); + BuildWebServiceMenu(); + } + + }); + } + }); addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() { public void internalFrameClosed( @@ -537,6 +565,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // System.out.println("deregistering discoverer listener"); Desktop.discoverer.removePropertyChangeListener(thisListener); + jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + .removePropertyChangeListener(thatListener); closeMenuItem_actionPerformed(true); }; }); @@ -3783,97 +3813,135 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return tp; } + private boolean buildingMenu = false; + /** * Generates menu items and listener event actions for web service clients * */ public void BuildWebServiceMenu() { - // TODO: add support for context dependent disabling of services based on - // alignment and current selection - // TODO: add additional serviceHandle parameter to specify abstract handler - // class independently of AbstractName - // TODO: add in rediscovery GUI function to restart discoverer - // TODO: group services by location as well as function and/or introduce - // object broker mechanism. - if ((Discoverer.services != null) && (Discoverer.services.size() > 0)) - { - // TODO: refactor to allow list of AbstractName/Handler bindings to be - // stored or retrieved from elsewhere - Vector msaws = (Vector) Discoverer.services.get("MsaWS"); - Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred"); - Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch"); - // TODO: move GUI generation code onto service implementation - so a - // client instance attaches itself to the GUI with method call like - // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, - // alignframe) + while (buildingMenu) + { + try + { + System.err.println("Waiting for building menu to finish."); + Thread.sleep(10); + } catch (Exception e) + { + } + ; + } + buildingMenu = true; + try + { + System.err + .println("Building ws menu again " + Thread.currentThread()); + // TODO: add support for context dependent disabling of services based on + // alignment and current selection + // TODO: add additional serviceHandle parameter to specify abstract + // handler + // class independently of AbstractName + // TODO: add in rediscovery GUI function to restart discoverer + // TODO: group services by location as well as function and/or introduce + // object broker mechanism. Vector wsmenu = new Vector(); final IProgressIndicator af = this; - if (msaws != null) + if ((Discoverer.services != null) && (Discoverer.services.size() > 0)) { - // Add any Multiple Sequence Alignment Services - final JMenu msawsmenu = new JMenu("Alignment"); - for (int i = 0, j = msaws.size(); i < j; i++) + // TODO: refactor to allow list of AbstractName/Handler bindings to be + // stored or retrieved from elsewhere + Vector msaws = (Vector) Discoverer.services.get("MsaWS"); + Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred"); + Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch"); + // TODO: move GUI generation code onto service implementation - so a + // client instance attaches itself to the GUI with method call like + // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, + // alignframe) + if (msaws != null) { - final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws - .get(i); - jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer - .getServiceClient(sh); - impl.attachWSMenuEntry(msawsmenu, this); + // Add any Multiple Sequence Alignment Services + final JMenu msawsmenu = new JMenu("Alignment"); + for (int i = 0, j = msaws.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws + .get(i); + jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer + .getServiceClient(sh); + impl.attachWSMenuEntry(msawsmenu, this); + } + wsmenu.add(msawsmenu); } - wsmenu.add(msawsmenu); - } - if (secstrpr != null) - { - // Add any secondary structure prediction services - final JMenu secstrmenu = new JMenu("Secondary Structure Prediction"); - for (int i = 0, j = secstrpr.size(); i < j; i++) + if (secstrpr != null) { - final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr - .get(i); - jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer - .getServiceClient(sh); - impl.attachWSMenuEntry(secstrmenu, this); + // Add any secondary structure prediction services + final JMenu secstrmenu = new JMenu( + "Secondary Structure Prediction"); + for (int i = 0, j = secstrpr.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr + .get(i); + jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer + .getServiceClient(sh); + impl.attachWSMenuEntry(secstrmenu, this); + } + wsmenu.add(secstrmenu); } - wsmenu.add(secstrmenu); - } - if (seqsrch != null) - { - // Add any sequence search services - final JMenu seqsrchmenu = new JMenu("Sequence Database Search"); - for (int i = 0, j = seqsrch.size(); i < j; i++) + if (seqsrch != null) { - final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch - .elementAt(i); - jalview.ws.WSMenuEntryProviderI impl = jalview.ws.Discoverer - .getServiceClient(sh); - impl.attachWSMenuEntry(seqsrchmenu, this); + // Add any sequence search services + final JMenu seqsrchmenu = new JMenu("Sequence Database Search"); + for (int i = 0, j = seqsrch.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch + .elementAt(i); + jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer + .getServiceClient(sh); + impl.attachWSMenuEntry(seqsrchmenu, this); + } + wsmenu.add(seqsrchmenu); } - wsmenu.add(seqsrchmenu); } + // TODO: move into separate menu builder class. { Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer(); - if (jws2servs!=null && jws2servs.hasServices()) + if (jws2servs != null) { - JMenu jws2men = new JMenu("Jalview 2 Services"); - jws2servs.attachWSMenuEntry(jws2men, this); - wsmenu.add(jws2men); + if (jws2servs.hasServices()) + { + JMenu jws2men = new JMenu("Jalview 2 Services"); + jws2servs.attachWSMenuEntry(jws2men, this); + wsmenu.add(jws2men); + } + else + { + if (!jws2servs.isRunning()) + { + new Thread(jws2servs).start(); + } + } } } - // finally, add the whole shebang onto the webservices menu resetWebServiceMenu(); - for (int i = 0, j = wsmenu.size(); i < j; i++) + // finally, add the whole shebang onto the webservices menu + if (wsmenu.size() > 0) { - webService.add((JMenu) wsmenu.get(i)); + for (int i = 0, j = wsmenu.size(); i < j; i++) + { + webService.add((JMenu) wsmenu.get(i)); + } } - } - else + else + { + this.webService.add(this.webServiceNoServices); + } + } catch (Exception e) { - resetWebServiceMenu(); - this.webService.add(this.webServiceNoServices); } + ; + buildingMenu = false; } /** diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 471a40a..8d824d7 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -63,7 +63,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements static final int yOffset = 30; - public static jalview.ws.Discoverer discoverer; + public static jalview.ws.jws1.Discoverer discoverer; public static Object[] jalviewClipboard; @@ -155,7 +155,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } }); - discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is + discoverer = new jalview.ws.jws1.Discoverer(); // Only gets started if gui is // displayed. // Thread off a new instance of the file chooser - this reduces the time it // takes to open it later on. diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 2d8eaa6..164725b 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -2,6 +2,7 @@ package jalview.ws.jws2; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.net.ConnectException; import java.util.HashSet; import java.util.Vector; @@ -27,7 +28,32 @@ import compbio.ws.client.Jws2Base.Services; */ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { - compbio.data.msa.MsaWS service; + private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this); + + /** + * change listeners are notified of "services" property changes + * + * @param listener + * to be added that consumes new services Hashtable object. + */ + public void addPropertyChangeListener( + java.beans.PropertyChangeListener listener) + { + changeSupport.addPropertyChangeListener(listener); + } + + /** + * + * + * @param listener + * to be removed + */ + public void removePropertyChangeListener( + java.beans.PropertyChangeListener listener) + { + changeSupport.removePropertyChangeListener(listener); + } + boolean running=false; @Override public void run() @@ -53,8 +79,13 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI try { service = Jws2Base.connect(jwsservers, srv); - } catch (Exception e) + } + catch (Exception e) { + System.err.println("Jws2 Discoverer: Problem with "+jwsservers+" with service "+srv+":\n"+e.getMessage()); + if (!(e instanceof javax.xml.ws.WebServiceException)) { + e.printStackTrace(); + } } ; if (service != null) @@ -70,13 +101,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } 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; - + changeSupport.firePropertyChange("services", new Vector(), services); } /** @@ -88,11 +120,11 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ private void addService(String jwsservers, Services srv, MsaWS service2) { - Cache.log.info("Discovered service: " + jwsservers + " " - + srv.toString()); if (services==null) { services = new Vector(); } + System.out.println("Discovered service: " + jwsservers + " " + + srv.toString()); services.add(new Jws2Instance(jwsservers, "Align with " + srv.toString(), service2)); } @@ -186,7 +218,12 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI public boolean hasServices() { // TODO Auto-generated method stub - return services!=null && services.size()>0; + return !running && services!=null && services.size()>0; + } + + public boolean isRunning() + { + return running; } } -- 1.7.10.2