X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FMsaWSClient.java;h=0d5c22ec9e9c9e3a5f43d823458accaf03e3df9a;hb=b8d09897dacc7b0ad203982b4578e2c1d8929142;hp=94e19e794c1efd0d1f4a5d2fb29514a5f94d5d05;hpb=4eeaf2d61f7513947bd8c3a5988623ad29a8ce7a;p=jalview.git diff --git a/src/jalview/ws/MsaWSClient.java b/src/jalview/ws/MsaWSClient.java index 94e19e7..0d5c22e 100755 --- a/src/jalview/ws/MsaWSClient.java +++ b/src/jalview/ws/MsaWSClient.java @@ -26,28 +26,38 @@ import jalview.datamodel.*; import jalview.gui.*; -import org.apache.axis.client.*; - -import vamsas.objects.*; - -import java.awt.*; - import java.util.*; import javax.swing.*; -import javax.xml.namespace.QName; - -public class MsaWSClient extends WSClient { - /** - * server is a WSDL2Java generated stub for an archetypal MsaWSI service. +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ */ +public class MsaWSClient extends WSClient +{ + /** + * server is a WSDL2Java generated stub for an archetypal MsaWSI service. + */ ext.vamsas.MuscleWS server; + /** + * Creates a new MsaWSClient object. + * + * @param MsaWSName DOCUMENT ME! + * @param altitle DOCUMENT ME! + * @param msa DOCUMENT ME! + * @param submitGaps DOCUMENT ME! + * @param preserveOrder DOCUMENT ME! + */ public MsaWSClient(String MsaWSName, String altitle, SequenceI[] msa, - boolean submitGaps, boolean preserveOrder) { - if (setWebService(MsaWSName) == false) { + boolean submitGaps, boolean preserveOrder) + { + if (setWebService(MsaWSName) == false) + { JOptionPane.showMessageDialog(Desktop.desktop, "The Multiple Sequence Alignment Service named " + MsaWSName + " is unknown", "Internal Jalview Error", @@ -59,7 +69,8 @@ public class MsaWSClient extends WSClient { wsInfo = new jalview.gui.WebserviceInfo(WebServiceJobTitle, WebServiceReference); - if (!locateWebService()) { + if (!locateWebService()) + { return; } @@ -73,8 +84,10 @@ public class MsaWSClient extends WSClient { } // JBPNote Nasty object-global state setting methods shouldn't be allowed - private boolean setWebService(String MsaWSName) { - if (MsaWServices.info.containsKey(MsaWSName)) { + private boolean setWebService(String MsaWSName) + { + if (MsaWServices.info.containsKey(MsaWSName)) + { WebServiceName = MsaWSName; String[] wsinfo = (String[]) MsaWServices.info.get(MsaWSName); @@ -83,19 +96,30 @@ public class MsaWSClient extends WSClient { WebServiceReference = wsinfo[2]; return true; - } else { + } + else + { return false; } } - private boolean locateWebService() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + private boolean locateWebService() + { // TODO: MuscleWS transmuted to generic MsaWS client MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default - try { + try + { this.server = (MuscleWS) loc.getMuscleWS(new java.net.URL(WsURL)); ((MuscleWSSoapBindingStub) this.server).setTimeout(60000); // One minute timeout - } catch (Exception ex) { + } + catch (Exception ex) + { wsInfo.setProgressText("Serious! " + WebServiceName + " Service location failed\nfor URL :" + WsURL + "\n" + ex.getMessage()); @@ -110,7 +134,8 @@ public class MsaWSClient extends WSClient { return true; } - protected class MsaWSThread extends Thread implements WSClientI { + protected class MsaWSThread extends Thread implements WSClientI + { String ServiceName = WebServiceName; String OutputHeader; vamsas.objects.simple.MsaResult result = null; @@ -124,7 +149,8 @@ public class MsaWSClient extends WSClient { boolean jobComplete = false; MsaWSThread(String title, SequenceI[] msa, boolean subgaps, - boolean presorder) { + boolean presorder) + { alTitle = title; submitGaps = subgaps; preserveOrder = presorder; @@ -134,7 +160,8 @@ public class MsaWSClient extends WSClient { vamsas.objects.simple.Sequence[] seqarray = new vamsas.objects.simple.Sequence[msa.length]; - for (int i = 0; i < msa.length; i++) { + for (int i = 0; i < msa.length; i++) + { String newname = jalview.analysis.SeqsetUtils.unique_name(i); // uniquify as we go @@ -152,85 +179,114 @@ public class MsaWSClient extends WSClient { this.seqs.setSeqs(seqarray); } - public boolean isCancellable() { + public boolean isCancellable() + { return true; } - public void cancelJob() { - if ((jobId != null) && !jobId.equals("") && !jobComplete) { + public void cancelJob() + { + if ((jobId != null) && !jobId.equals("") && !jobComplete) + { String cancelledMessage = ""; - try { + try + { vamsas.objects.simple.WsJobId cancelledJob = server.cancel(jobId); - if (cancelledJob.getStatus() == 2) { + if (cancelledJob.getStatus() == 2) + { // CANCELLED_JOB cancelledMessage = "Job cancelled."; wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK); jobComplete = true; jobsRunning--; result = null; - } else if (cancelledJob.getStatus() == 3) { + } + else if (cancelledJob.getStatus() == 3) + { // VALID UNSTOPPABLE JOB cancelledMessage += "Server cannot cancel this job. just close the window.\n"; } - if (cancelledJob.getJobId() != null) { + if (cancelledJob.getJobId() != null) + { cancelledMessage += ("[" + cancelledJob.getJobId() + "]"); } cancelledMessage += "\n"; - } catch (Exception exc) { + } + catch (Exception exc) + { cancelledMessage += ("\nProblems cancelling the job : Exception received...\n" + exc + "\n"); exc.printStackTrace(); } wsInfo.setProgressText(OutputHeader + cancelledMessage + "\n"); - } else { - if (!jobComplete) { + } + else + { + if (!jobComplete) + { wsInfo.setProgressText(OutputHeader + "Server cannot cancel this job because it has not been submitted properly. just close the window.\n"); } } } - public void run() { + public void run() + { StartJob(); - while (!jobComplete && (allowedServerExceptions > 0)) { - try { - if ((result = server.getResult(jobId)) == null) { + while (!jobComplete && (allowedServerExceptions > 0)) + { + try + { + if ((result = server.getResult(jobId)) == null) + { throw (new Exception( "Timed out when communicating with server\nTry again later.\n")); } - if (result.isRunning()) { + if (result.isRunning()) + { wsInfo.setStatus(WebserviceInfo.STATE_RUNNING); - } else if (result.isQueued()) { + } + else if (result.isQueued()) + { wsInfo.setStatus(WebserviceInfo.STATE_QUEUING); } - if (result.isFinished()) { + if (result.isFinished()) + { parseResult(); jobComplete = true; jobsRunning--; - } else { - if (result.getStatus() != null) { + } + else + { + if (result.getStatus() != null) + { wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus()); } - if (!(result.isJobFailed() || result.isServerError())) { + if (!(result.isJobFailed() || result.isServerError())) + { Thread.sleep(5000); // System.out.println("I'm alive "+seqid+" "+jobid); - } else { + } + else + { break; } } - } catch (Exception ex) { + } + catch (Exception ex) + { allowedServerExceptions--; wsInfo.appendProgressText("\n" + ServiceName + " Server exception!\n" + ex.getMessage()); @@ -238,59 +294,81 @@ public class MsaWSClient extends WSClient { ex.getMessage()); // ex.printStackTrace(); JBPNote Debug - try { - if (allowedServerExceptions > 0) { + try + { + if (allowedServerExceptions > 0) + { Thread.sleep(5000); } - } catch (InterruptedException ex1) { + } + catch (InterruptedException ex1) + { } } } - if (allowedServerExceptions == 0) { + if (allowedServerExceptions == 0) + { wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); - } else { + } + else + { if (!((result != null) && - (result.isJobFailed() || result.isServerError()))) { + (result.isJobFailed() || result.isServerError()))) + { wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK); - } else { - if (result.isFailed()) { + } + else + { + if (result.isFailed()) + { wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); } - if (result.isServerError()) { + if (result.isServerError()) + { wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR); } } } } - void StartJob() { - try { + void StartJob() + { + try + { vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs); - if ((jobsubmit != null) && (jobsubmit.getStatus() == 1)) { + if ((jobsubmit != null) && (jobsubmit.getStatus() == 1)) + { jobId = jobsubmit.getJobId(); System.out.println(WsURL + " Job Id '" + jobId + "'"); - } else { - if (jobsubmit == null) { + } + else + { + if (jobsubmit == null) + { throw new Exception("Server at " + WsURL + " returned null object, it probably cannot be contacted. Try again later ?"); } throw new Exception(jobsubmit.getJobId()); } - } catch (Exception e) { + } + catch (Exception e) + { // TODO: JBPNote catch timeout or other fault types explicitly // For unexpected errors System.err.println(WebServiceName + - "Client: Failed to submit the sequences for alignment (probably a server side problem)\n" - + "When contacting Server:"+WsURL + "\n" + e.toString() + "\n"); + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n" + + "When contacting Server:" + WsURL + "\n" + e.toString() + + "\n"); this.allowedServerExceptions = 0; wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR); - wsInfo.appendProgressText("Failed to submit sequences for alignment.\n" - + "It is most likely that there is a problem with the server.\n" - + "Just close the window\n"); + wsInfo.appendProgressText( + "Failed to submit sequences for alignment.\n" + + "It is most likely that there is a problem with the server.\n" + + "Just close the window\n"); // e.printStackTrace(); // TODO: JBPNote DEBUG } @@ -298,10 +376,12 @@ public class MsaWSClient extends WSClient { private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, - float max, int winLength) { + float max, int winLength) + { Annotation[] annotations = new Annotation[al.getWidth()]; - for (int j = 0; j < values.size(); j++) { + for (int j = 0; j < values.size(); j++) + { float value = Float.parseFloat(values.get(j).toString()); annotations[gapmap[j]] = new Annotation("", value + "", ' ', value); @@ -312,7 +392,8 @@ public class MsaWSClient extends WSClient { } private jalview.datamodel.Sequence[] getVamsasAlignment( - vamsas.objects.simple.Alignment valign) { + vamsas.objects.simple.Alignment valign) + { vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs(); jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs.length]; @@ -323,20 +404,25 @@ public class MsaWSClient extends WSClient { return msa; } - void parseResult() { + void parseResult() + { SequenceI[] seqs = null; - try { + try + { // OutputHeader = output.getText(); - if (result.isFailed()) { + if (result.isFailed()) + { OutputHeader += "Job failed.\n"; } - if (result.getStatus() != null) { + if (result.getStatus() != null) + { OutputHeader += ("\n" + result.getStatus()); } - if (result.getMsa() != null) { + if (result.getMsa() != null) + { OutputHeader += "\nAlignment Object Method Notes\n"; String[] lines = result.getMsa().getMethod(); @@ -350,10 +436,12 @@ public class MsaWSClient extends WSClient { wsInfo.setProgressText(OutputHeader); - if (seqs != null) { + if (seqs != null) + { AlignmentOrder msaorder = new AlignmentOrder(seqs); - if (preserveOrder) { + if (preserveOrder) + { jalview.analysis.AlignmentSorter.recoverOrder(seqs); } @@ -370,7 +458,9 @@ public class MsaWSClient extends WSClient { AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); } - } catch (Exception ex) { + } + catch (Exception ex) + { ex.printStackTrace(); } }