e6d176a70d60765870881c2fe1942098292121ac
[jalview.git] / src / jalview / ws / JobStateSummary.java
1 package jalview.ws;
2
3 import jalview.gui.WebserviceInfo;
4
5 /**
6  * bookkeeper class for the WebServiceInfo GUI, maintaining records of web
7  * service jobs handled by the window and reflecting any status updates.
8  * 
9  * @author JimP
10  * 
11  */
12 public class JobStateSummary
13 {
14   /**
15    * number of jobs running
16    */
17   int running = 0;
18
19   /**
20    * number of jobs queued
21    */
22   int queuing = 0;
23
24   /**
25    * number of jobs finished
26    */
27   int finished = 0;
28
29   /**
30    * number of jobs failed
31    */
32   int error = 0;
33
34   /**
35    * number of jobs stopped due to server error
36    */
37   int serror = 0;
38
39   /**
40    * number of jobs cancelled
41    */
42   int cancelled = 0;
43
44   /**
45    * number of jobs finished with results
46    */
47   int results = 0;
48
49   /**
50    * processes an AWSJob's status and updates job status counters and WebService
51    * status displays
52    * 
53    * @param wsInfo
54    * @param OutputHeader
55    * @param j
56    */
57   public void updateJobPanelState(WebserviceInfo wsInfo,
58           String OutputHeader, AWsJob j)
59   {
60     if (j.submitted)
61     {
62       String progheader = "";
63       // Parse state of job[j]
64       if (j.isRunning())
65       {
66         running++;
67         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_RUNNING);
68       }
69       else if (j.isQueued())
70       {
71         queuing++;
72         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_QUEUING);
73       }
74       else if (j.isFinished())
75       {
76         finished++;
77         j.subjobComplete = true;
78         if (j.hasResults())
79         {
80           results++;
81         }
82         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_OK);
83       }
84       else if (j.isFailed())
85       {
86         progheader += "Job failed.\n";
87         j.subjobComplete = true;
88         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
89         error++;
90       }
91       else if (j.isServerError())
92       {
93         serror++;
94         j.subjobComplete = true;
95         wsInfo
96                 .setStatus(j.jobnum,
97                         WebserviceInfo.STATE_STOPPED_SERVERERROR);
98       }
99       else if (j.isBroken())
100       {
101         progheader += "Job was broken.\n";
102         error++;
103         j.subjobComplete = true;
104         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
105       }
106       // and pass on any sub-job messages to the user
107       wsInfo.setProgressText(j.jobnum, OutputHeader);
108       wsInfo.appendProgressText(j.jobnum, progheader);
109       if (j.hasStatus())
110       {
111         // Could try to squash OOMs here, but it usually doesn't help - there probably won't be
112         // enough memory to handle the results later on anyway.
113         // try {
114         wsInfo.appendProgressText(j.jobnum, j.getStatus());
115         // } catch (OutOfMemoryError e)
116         // {
117         // System.err.println("Out of memory when displaying status. Squashing error.");
118         // wsInfo.appendProgressText(j.jobnum,
119         // "..\n(Out of memory when displaying status)\n");
120         // }
121       }
122     }
123     else
124     {
125       if (j.submitted && j.subjobComplete)
126       {
127         if (j.allowedServerExceptions == 0)
128         {
129           serror++;
130         }
131         else if (!j.hasResults())
132         {
133           error++;
134         }
135       }
136     }
137   }
138 }