1 package jalview.ws2.api;
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
7 import jalview.util.MathUtils;
10 * {@code WebServiceJob} represents a job running on a remote server. The object
11 * contains all the information needed to associate the job with an originating
12 * client and url, service being run and to poll the job and retrieve the
13 * results from the server. The {@code WebServiceJob} object is provided by the
14 * {@link WebServiceClientI#submit} method when the job is created.
16 * @see WebServiceClientI
20 public class WebServiceJob
22 /** Unique id used internally by Jalview */
23 private final long internalId = MathUtils.getUID();
25 /** Name of the related client */
26 private final String serviceClient;
28 /** Name of the related service */
29 private final String serviceName;
31 /** URL the job is valid for */
32 private final String url;
34 /** External job id as given by the server */
35 private final String jobId;
37 /** Current status of the job */
38 private JobStatus status = JobStatus.READY;
40 private String log = "";
42 private String errorLog = "";
44 private Date creationTime = new Date();
46 public WebServiceJob(String serviceClient, String serviceName,
47 String url, String jobId)
49 this.serviceClient = serviceClient;
50 this.serviceName = serviceName;
56 * Get a unique job id used internally by Jalview.
58 * @return unique job id
60 public long getInternalId()
66 * Get a URL this job originates from.
70 public String getUrl()
76 * Get an id assigned to the job by the server.
78 * @return job id handle
80 public String getJobId()
88 public JobStatus getStatus()
94 * Update status of the job and notify the listeners. This method should only
95 * be used by {@link WebServiceClientI} implementations when polling the job.
100 public void setStatus(JobStatus status)
102 JobStatus oldStatus = this.status;
103 this.status = status;
104 pcs.firePropertyChange("status", oldStatus, status);
108 * @return standard progress log
110 public String getLog()
116 * Update log string with data received from the server and notify the
117 * listeners. This method should only be used by {@link WebServiceClientI}
118 * implementations when polling the job.
123 public void setLog(String log)
125 String oldLog = this.log;
127 pcs.firePropertyChange("log", oldLog, log);
133 public String getErrorLog()
139 * Update error log string with data received from the server and notify the
140 * listeners. This method should only be used by {@link WebServiceClientI}
141 * implementations when polling the job
144 * new error log string
146 public void setErrorLog(String errorLog)
148 String oldLog = this.errorLog;
149 this.errorLog = errorLog;
150 pcs.firePropertyChange("errorLog", oldLog, errorLog);
154 * @return Job creation time
156 public Date getCreationTime()
161 public String toString()
163 return String.format("%s:%s [%s] Created %s", serviceClient, serviceName,
164 jobId, creationTime);
167 /* Methods related to bean listeners */
168 private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
170 public void addPropertyChangeListener(PropertyChangeListener listener)
172 pcs.addPropertyChangeListener(listener);
175 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
177 pcs.addPropertyChangeListener(propertyName, listener);
180 public void removePropertyChangeListener(PropertyChangeListener listener)
182 pcs.removePropertyChangeListener(listener);
185 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
187 pcs.removePropertyChangeListener(propertyName, listener);