update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / JobStateSummary.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.ws;
19
20 import jalview.gui.WebserviceInfo;
21
22 /**
23  * bookkeeper class for the WebServiceInfo GUI, maintaining records of web
24  * service jobs handled by the window and reflecting any status updates.
25  * 
26  * @author JimP
27  * 
28  */
29 public class JobStateSummary
30 {
31   /**
32    * number of jobs running
33    */
34   int running = 0;
35
36   /**
37    * number of jobs queued
38    */
39   int queuing = 0;
40
41   /**
42    * number of jobs finished
43    */
44   int finished = 0;
45
46   /**
47    * number of jobs failed
48    */
49   int error = 0;
50
51   /**
52    * number of jobs stopped due to server error
53    */
54   int serror = 0;
55
56   /**
57    * number of jobs cancelled
58    */
59   int cancelled = 0;
60
61   /**
62    * number of jobs finished with results
63    */
64   int results = 0;
65
66   /**
67    * processes an AWSJob's status and updates job status counters and WebService
68    * status displays
69    * 
70    * @param wsInfo
71    * @param OutputHeader
72    * @param j
73    */
74   public void updateJobPanelState(WebserviceInfo wsInfo,
75           String OutputHeader, AWsJob j)
76   {
77     if (j.submitted)
78     {
79       String progheader = "";
80       // Parse state of job[j]
81       if (j.isRunning())
82       {
83         running++;
84         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_RUNNING);
85       }
86       else if (j.isQueued())
87       {
88         queuing++;
89         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_QUEUING);
90       }
91       else if (j.isFinished())
92       {
93         finished++;
94         j.subjobComplete = true;
95         if (j.hasResults())
96         {
97           results++;
98         }
99         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_OK);
100       }
101       else if (j.isFailed())
102       {
103         progheader += "Job failed.\n";
104         j.subjobComplete = true;
105         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
106         error++;
107       }
108       else if (j.isServerError())
109       {
110         serror++;
111         j.subjobComplete = true;
112         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_SERVERERROR);
113       }
114       else if (j.isBroken())
115       {
116         progheader += "Job was broken.\n";
117         error++;
118         j.subjobComplete = true;
119         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
120       }
121       // and pass on any sub-job messages to the user
122       StringBuffer output=new StringBuffer();
123       if (OutputHeader!=null) {
124         
125         output.append(OutputHeader);
126       }
127       if (progheader!=null)
128       {
129         output.append(progheader);
130       }
131       if (j.hasStatus())
132       {
133         // Could try to squash OOMs here, but it usually doesn't help - there
134         // probably won't be
135         // enough memory to handle the results later on anyway.
136         // try {
137         String stat =  j.getStatus();
138         if (stat!=null) {
139           output.append(stat);
140         }
141         // } catch (OutOfMemoryError e)
142         // {
143         // System.err.println("Out of memory when displaying status. Squashing error.");
144         // wsInfo.appendProgressText(j.jobnum,
145         // "..\n(Out of memory when displaying status)\n");
146         // }
147       }
148       wsInfo.setProgressText(j.jobnum,output.toString());
149     }
150     else
151     {
152       if (j.submitted && j.subjobComplete)
153       {
154         if (j.allowedServerExceptions == 0)
155         {
156           serror++;
157         }
158         else if (!j.hasResults())
159         {
160           error++;
161         }
162       }
163     }
164   }
165 }