use of org.geotoolkit.wps.xml.v200.StatusInfo in project geotoolkit by Geomatys.
the class WPS2Process method checkResult.
/**
* A Function to ensure response object is success or failure. Otherwise, we request continually status until
* we reach a result.
*
* @param response The execute response given by service.
*/
private Result checkResult(Object response) throws IOException, JAXBException, InterruptedException, ProcessException {
if (response instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) response;
throw new ProcessException("Exception when executing the process.", this, report.toException());
} else if (response instanceof StatusInfo) {
final StatusInfo statusInfo = (StatusInfo) response;
Status status = statusInfo.getStatus();
jobId = statusInfo.getJobID();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else if (Status.ACCEPTED.equals(status)) {
// Initial status
fireProgressing("Process accepted: " + jobId, 0, false);
} else {
// Running
final Integer progress = statusInfo.getPercentCompleted();
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
fireProgressing(message, progress == null ? Float.NaN : progress, false);
}
// loop until we have an answer
Object tmpResponse;
// TODO : make timelapse configurable
int timeLapse = 3000;
// we tolerate a few unmarshalling or IO errors, the servers behave differentely
// and may not offer the result file right from the start
int failCount = 0;
while (true) {
stopIfDismissed();
synchronized (this) {
wait(timeLapse);
}
try {
tmpResponse = getStatus();
failCount = 0;
} catch (UnmarshalException | IOException ex) {
if (failCount < 5 && !isDimissed()) {
failCount++;
continue;
} else if (isDimissed()) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else {
// happenning so we consider the process failed
throw ex;
}
}
if (tmpResponse instanceof StatusInfo) {
final StatusInfo statInfo = (StatusInfo) tmpResponse;
status = statInfo.getStatus();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
}
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
final Integer percentCompleted = statInfo.getPercentCompleted();
if (!Objects.equals(message, lastMessage) || !Objects.equals(percentCompleted, lastProgress)) {
lastMessage = message;
lastProgress = percentCompleted;
fireProgressing(lastMessage, lastProgress, false);
}
} else if (tmpResponse instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) tmpResponse;
throw new ProcessException("Exception when executing the process.", this, report.toException());
}
}
} else if (response instanceof Result) {
final Result result = checkLegacyResult((Result) response);
if (result.getJobID() != null) {
jobId = result.getJobID();
}
return result;
} else {
throw new ProcessException("Unexpected response " + response, this);
}
}
use of org.geotoolkit.wps.xml.v200.StatusInfo in project geotoolkit by Geomatys.
the class WPS2Process method getStatus.
/**
* Get current task status.<br>
*
* This method should not be called if process is not running.
*
* @return StatusInfo
* @throws org.geotoolkit.process.ProcessException
* @throws javax.xml.bind.UnmarshalException
* @throws java.io.IOException
*/
private StatusInfo getStatus() throws ProcessException, JAXBException, IOException {
if (jobId == null)
throw new ProcessException("Process is not started.", this);
if (isDimissed()) {
throw new DismissProcessException("Process already dismissed", this);
}
final GetStatusRequest req = registry.getClient().createGetStatus(jobId);
req.setDebug(debug);
req.setClientSecurity(security);
final Object response = req.getResponse();
if (response instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) response;
throw new ProcessException("Exception when executing the process.", this, report.toException());
} else if (response instanceof StatusInfo) {
return (StatusInfo) response;
} else {
throw new ProcessException("Unexpected response " + response.getClass().getName(), this);
}
}
Aggregations