1 package jalview.ws2.client.api;
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
7 import jalview.util.MathUtils;
8 import jalview.ws2.api.JobStatus;
11 * {@code WebServiceJob} represents a job running on a remote server. The object
12 * contains all the information needed to associate the job with an originating
13 * client and url, service being run and to poll the job and retrieve the
14 * results from the server. The {@code WebServiceJob} object is provided by the
15 * {@link WebServiceClientI#submit} method when the job is created.
17 * @see WebServiceClientI
21 public class WebServiceJob
23 /** Unique id used internally by Jalview */
24 private final long internalId = MathUtils.getUID();
26 /** Name of the related client */
27 private final String serviceClient;
29 /** Name of the related service */
30 private final String serviceName;
32 /** URL the job is valid for */
33 private final String url;
35 /** External job id as given by the server */
36 private final String jobId;
38 /** Current status of the job */
39 private JobStatus status = JobStatus.READY;
41 private String log = "";
43 private String errorLog = "";
45 private Date creationTime = new Date();
47 public WebServiceJob(String serviceClient, String serviceName,
48 String url, String jobId)
50 this.serviceClient = serviceClient;
51 this.serviceName = serviceName;
57 * Get a unique job id used internally by Jalview.
59 * @return unique job id
61 public long getInternalId()
67 * Get a URL this job originates from.
71 public String getUrl()
77 * Get an id assigned to the job by the server.
79 * @return job id handle
81 public String getJobId()
89 public JobStatus getStatus()
95 * Update status of the job and notify the listeners. This method should only
96 * be used by {@link WebServiceClientI} implementations when polling the job.
101 public void setStatus(JobStatus status)
103 JobStatus oldStatus = this.status;
104 this.status = status;
105 pcs.firePropertyChange("status", oldStatus, status);
109 * @return standard progress log
111 public String getLog()
117 * Update log string with data received from the server and notify the
118 * listeners. This method should only be used by {@link WebServiceClientI}
119 * implementations when polling the job.
124 public void setLog(String log)
126 String oldLog = this.log;
128 pcs.firePropertyChange("log", oldLog, log);
134 public String getErrorLog()
140 * Update error log string with data received from the server and notify the
141 * listeners. This method should only be used by {@link WebServiceClientI}
142 * implementations when polling the job
145 * new error log string
147 public void setErrorLog(String errorLog)
149 String oldLog = this.errorLog;
150 this.errorLog = errorLog;
151 pcs.firePropertyChange("errorLog", oldLog, errorLog);
155 * @return Job creation time
157 public Date getCreationTime()
162 public String toString()
164 return String.format("%s:%s [%s] Created %s", serviceClient, serviceName,
165 jobId, creationTime);
168 /* Methods related to bean listeners */
169 private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
171 public void addPropertyChangeListener(PropertyChangeListener listener)
173 pcs.addPropertyChangeListener(listener);
176 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
178 pcs.addPropertyChangeListener(propertyName, listener);
181 public void removePropertyChangeListener(PropertyChangeListener listener)
183 pcs.removePropertyChangeListener(listener);
186 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
188 pcs.removePropertyChangeListener(propertyName, listener);