3 import static java.lang.String.format;
5 import java.util.Hashtable;
8 import jalview.bin.Cache;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.AlignmentView;
12 import jalview.datamodel.HiddenColumns;
13 import jalview.datamodel.SequenceI;
14 import jalview.gui.AlignFrame;
15 import jalview.gui.Desktop;
16 import jalview.gui.WebserviceInfo;
17 import jalview.util.MessageManager;
18 import jalview.ws.api.CancellableI;
19 import jalview.ws.api.JPredMutlipleAlignmentServiceI;
20 import jalview.ws.gui.WsJob;
21 import jalview.ws.gui.WsJob.JobState;
24 class JPredJob extends WsJob
26 Hashtable<?, ?> sequenceInfo;
29 public AlignmentI alignment;
31 public JPredJob(Hashtable<?, ?> sequenceInfo, SequenceI[] msf, int[] delMap)
33 this.sequenceInfo = sequenceInfo;
34 this.msf = List.of(msf);
39 public boolean hasValidInput()
46 public class JPredThread extends AWSThread implements WSClientI
49 private JPredMutlipleAlignmentServiceI server;
51 private Hashtable<?, ?> sequenceInfo;
52 private SequenceI[] msf;
55 public JPredThread(WebserviceInfo wsInfo, String title,
56 JPredMutlipleAlignmentServiceI server, Hashtable<?, ?> sequenceInfo,
57 SequenceI[] msf, int[] delMap, AlignmentView view, AlignFrame frame,
60 super(frame, wsInfo, view, wsURL);
63 this.sequenceInfo = sequenceInfo;
66 JPredJob job = new JPredJob(sequenceInfo, msf, delMap);
67 this.jobs = new JPredJob[] { job };
71 public boolean isCancellable()
73 return server instanceof CancellableI;
77 public boolean canMergeResults()
83 public void cancelJob()
85 // TODO Auto-generated method stub
90 public void pollJob(AWsJob job_) throws Exception
92 var job = (JPredJob) job_;
93 server.updateStatus(job);
94 server.updateJobProgress(job);
98 public void StartJob(AWsJob job_)
100 if (!(job_ instanceof JPredJob))
101 throw new RuntimeException("Invalid job type");
102 var job = (JPredJob) job_;
103 if (job.isSubmitted())
110 var jobHandle = server.align(job.msf);
111 if (jobHandle != null)
112 job.setJobHandle(jobHandle);
114 catch (Throwable th) {
115 if (!server.handleSubmitError(th, job, wsInfo)) {
119 if (job.getJobId() != null) {
120 job.setSubmitted(true);
121 job.setSubjobComplete(false);
125 throw new Exception(MessageManager.formatMessage(
126 "exception.web_service_returned_null_try_later",
133 // For unexpected errors
134 System.err.println(WebServiceName
135 + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n"
136 + "When contacting Server:" + WsUrl + "\n");
137 th.printStackTrace(System.err);
138 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
139 wsInfo.setStatus(job.getJobnum(),
140 WebserviceInfo.STATE_STOPPED_SERVERERROR);
145 if (!job.isSubmitted())
147 job.setAllowedServerExceptions(0);
148 wsInfo.appendProgressText(job.getJobnum(), MessageManager.getString(
149 "info.failed_to_submit_sequences_for_alignment"));
155 public void parseResult()
157 long progbar = (long) (Math.random() * ~(1L << 63));
158 wsInfo.setProgressBar(
159 MessageManager.getString("status.collecting_job_results"), progbar);
161 var finalState = new JobStateSummary();
164 for (int i = 0; i < jobs.length; i++) {
165 final var job = (JPredJob) jobs[i];
166 finalState.updateJobPanelState(wsInfo, OutputHeader, job);
167 if (job.isFinished()) {
169 server.updateJobProgress(job);
171 catch (Exception e) {
172 Cache.log.warn(format(
173 "Exception when retrieving remaining Job progress data " +
174 "for job %s on server %s", job.getJobId(), WsUrl));
177 // removed the waiting loop
178 Cache.log.debug(format("Job Execution file for job: %s " +
179 "on server %s%n%s", job.getJobId(), WsUrl, job.getStatus()));
181 job.alignment = server.getResult(job.getJobHandle());
183 catch (Exception e) {
184 if (!server.handleCollectionException(e, job, wsInfo)) {
185 Cache.log.error("Could not get alignment for job.", e);
186 job.setState(JobState.SERVERERROR);
190 finalState.updateJobPanelState(wsInfo, OutputHeader, job);
191 if (job.isSubmitted() && job.isSubjobComplete() && job.hasResults()) {
196 catch (Exception e) {
198 "Unexpected exception when processing results for " + title, e);
199 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
202 wsInfo.showResultsNewFrame.addActionListener(
203 (evt) -> displayResults(true));
204 wsInfo.mergeResults.addActionListener(
205 (evt) -> displayResults(false));
206 wsInfo.setResultsReady();
209 wsInfo.setFinishedNoResults();
211 updateGlobalStatus(finalState);
212 wsInfo.removeProgressBar(progbar);
217 private void displayResults(boolean newWindow)
219 System.out.println("DISPLAYING THE RESULT");