/** * Processes a given Processing through the CallStack of this executor. Note that if a DocumentProcessor * returns a LaterProgress for this processing, it will be re-processed (after waiting the specified delay given * by the LaterProgress), until done or failed. * * @param processing the Processing to process. The CallStack of the Processing will be set to a clone of the CallStack of this executor, iff. it is currently null. * @return a Progress; this is never a LaterProgress. * @throws RuntimeException if a document processor throws an exception during processing, or this thread is interrupted while waiting. * @see com.yahoo.docproc.Processing * @see com.yahoo.docproc.DocumentProcessor.Progress * @see com.yahoo.docproc.DocumentProcessor.LaterProgress */ public DocumentProcessor.Progress processUntilDone(Processing processing) { DocumentProcessor.Progress progress; while (true) { progress = process(processing); if (!(progress instanceof DocumentProcessor.LaterProgress)) { break; } DocumentProcessor.LaterProgress later = (DocumentProcessor.LaterProgress) progress; try { Thread.sleep(later.getDelay()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } return progress; } }
@Override public void run() { try { try { processings.addAll(requestContext.getProcessings()); } catch (Exception e) { //deserialization failed: log.log(LogLevel.WARNING, "Deserialization of message failed.", e); requestContext.processingFailed(e); return; } DocprocExecutor executor = service.getExecutor(); DocumentProcessor.Progress progress = process(executor); if (DocumentProcessor.Progress.LATER.equals(progress) && !processings.isEmpty()) { DocumentProcessor.LaterProgress laterProgress = (DocumentProcessor.LaterProgress) progress; docprocHandler.submit(this, laterProgress.getDelay()); } } catch (Error error) { try { log.log(LogLevel.FATAL, Exceptions.toMessageString(error), error); } catch (Throwable t) { // do nothing } finally { Runtime.getRuntime().halt(1); } } }
public static Progress later(long delay) { return new LaterProgress(delay); }