Jalview 2.6 source licence
[jalview.git] / src / jalview / ws / JobStateSummary.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, 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
113                 .setStatus(j.jobnum,
114                         WebserviceInfo.STATE_STOPPED_SERVERERROR);
115       }
116       else if (j.isBroken())
117       {
118         progheader += "Job was broken.\n";
119         error++;
120         j.subjobComplete = true;
121         wsInfo.setStatus(j.jobnum, WebserviceInfo.STATE_STOPPED_ERROR);
122       }
123       // and pass on any sub-job messages to the user
124       wsInfo.setProgressText(j.jobnum, OutputHeader);
125       wsInfo.appendProgressText(j.jobnum, progheader);
126       if (j.hasStatus())
127       {
128         // Could try to squash OOMs here, but it usually doesn't help - there probably won't be
129         // enough memory to handle the results later on anyway.
130         // try {
131         wsInfo.appendProgressText(j.jobnum, j.getStatus());
132         // } catch (OutOfMemoryError e)
133         // {
134         // System.err.println("Out of memory when displaying status. Squashing error.");
135         // wsInfo.appendProgressText(j.jobnum,
136         // "..\n(Out of memory when displaying status)\n");
137         // }
138       }
139     }
140     else
141     {
142       if (j.submitted && j.subjobComplete)
143       {
144         if (j.allowedServerExceptions == 0)
145         {
146           serror++;
147         }
148         else if (!j.hasResults())
149         {
150           error++;
151         }
152       }
153     }
154   }
155 }