public void run() { DBObject obj = isJobRequested(); if (obj == null) { // if there is not current active request just make sure all // clients // have the latest solution broadcastLatestSolution(); } else { // if there is request, check its staus Object jobid = obj.get("jobid"); if (jobid == null) { // if the jobid was not assigned after 10 seconds, there // must be an issue // so cancel the request. Object ts = obj.get("ts"); Date now = new Date(); if (jobid == null && ts != null && (now.getTime() - ((Date) ts).getTime()) > 10000) { LOG.log(Level.WARNING, "Cancelling job because the jobid was not set"); requestJobDone(); broadcastLatestSolution(); } } else { // check execution status String id = (String) jobid; try { JobExecutionStatus status = jobclient.getJobExecutionStatus(id); switch (status) { case CREATED: case NOT_STARTED: case RUNNING: case INTERRUPTING: StatusEventEndpoint.broadcastStatus(new RequestStatus(true, id, status)); break; case FAILED: JobFailureInfo failure = jobclient.getFailureInfo(id); LOG.warning("Failed " + failure.getMessage()); StatusEventEndpoint.broadcastStatus( new RequestStatus(false, id, status, failure.getMessage())); try { jobclient.deleteJob(id); } catch (Exception e) { // ignore any exception } requestJobDone(); broadcastLatestSolution(); break; case INTERRUPTED: case PROCESSED: if (requestJobProcessed(id) != null) { completedAsync(id); } broadcastLatestSolution(); break; } } catch (JobNotFoundException e) { // job was not found, already processed requestJobDone(); broadcastLatestSolution(); } catch (OperationException e) { // ignore will retry at next monitor execution } } } }