/** * 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; } }
/** * Sets a new processing stack for this service. This will be the Prototype * for the call stacks of individual processings in this service */ public void setCallStack(CallStack stack) { DocprocExecutor ex = ((getExecutor() == null) ? new DocprocExecutor(getName(), stack) : new DocprocExecutor(getExecutor(), stack)); setExecutor(ex); }
/** * Returns the processing chain of this service. This stack can not be modified. * To change the stack, set a new one. */ // TODO: Enforce unmodifiability public CallStack getCallStack() { DocprocExecutor ex = getExecutor(); return (ex == null) ? null : ex.getCallStack(); }
processing.setServiceName(getName()); if (processing.callStack() == null) { processing.setCallStack(new CallStack(getCallStack())); incrementNumDocsProcessed(processing); do { Call call = processing.callStack().pop(); logProgress(processing, progress, call);
private void incrementNumDocsProcessed(Processing processing) { int increment = processing.getNumDocsToBeProcessed(); if (increment != 0) { incrementNumDocsProcessed(increment); } }
/** * Processes the given Processing through the specified chain. Note that if one * {@link com.yahoo.docproc.DocumentProcessor DocumentProcessor} in the * chain returns a {@link com.yahoo.docproc.DocumentProcessor.LaterProgress DocumentProcessor.LaterProgress}, * the calling thread will sleep for the duration * specified in {@link com.yahoo.docproc.DocumentProcessor.LaterProgress#getDelay() DocumentProcessor.LaterProgress#getDelay()}, * and then run again. This method will hence return when a document processor returns * {@link com.yahoo.docproc.DocumentProcessor.Progress#DONE DocumentProcessor.Progress#DONE} or * {@link com.yahoo.docproc.DocumentProcessor.Progress#FAILED DocumentProcessor.Progress#FAILED}, throws an exception, * or if the calling thread is interrupted. This method will never return a * {@link com.yahoo.docproc.DocumentProcessor.LaterProgress DocumentProcessor.LaterProgress}. * * @param chain the specification of the chain to execute * @param processing the Processing to process * @return Progress.DONE or Progress.FAILED * @throws RuntimeException if one of the document processors in the chain throws, or if the calling thread is interrupted */ public DocumentProcessor.Progress process(ComponentSpecification chain, com.yahoo.docproc.Processing processing) { DocprocExecutor executor = getExecutor(chain); processing.setDocprocServiceRegistry(handler.getDocprocServiceRegistry()); return executor.processUntilDone(processing); }
/** * Processes the given Processing through the specified chain. Note that if one * {@link com.yahoo.docproc.DocumentProcessor DocumentProcessor} in the * chain returns a {@link com.yahoo.docproc.DocumentProcessor.LaterProgress DocumentProcessor.LaterProgress}, * it will be returned by this method. This method will hence return whenever a document processor returns any * {@link com.yahoo.docproc.DocumentProcessor.Progress DocumentProcessor.Progress}, or * throws an exception. * * @param chain the specification of the chain to execute * @param processing the Processing to process * @return any Progress * @throws RuntimeException if one of the document processors in the chain throws */ public DocumentProcessor.Progress processOnce(ComponentSpecification chain, com.yahoo.docproc.Processing processing) { DocprocExecutor executor = getExecutor(chain); processing.setDocprocServiceRegistry(handler.getDocprocServiceRegistry()); return executor.process(processing); }
@Override public ContentChannel handleRequest(Request request, ResponseHandler handler) { RequestContext requestContext; if (request instanceof MbusRequest) { requestContext = new MbusRequestContext((MbusRequest) request, handler, docprocServiceRegistry, docFactoryRegistry, containerDocConfig); } else { //Other types can be added here in the future throw new IllegalArgumentException("Request type not supported: " + request); } if (!requestContext.isProcessable()) { requestContext.skip(); return null; } DocprocService service = docprocServiceRegistry.getComponent(requestContext.getServiceName()); //No need to enqueue a task if the docproc chain is empty, just forward requestContext if (service == null) { log.log(LogLevel.ERROR, "DocprocService for session '" + requestContext.getServiceName() + "' not found, returning request '" + requestContext + "'."); requestContext.processingFailed(RequestContext.ErrorCode.ERROR_PROCESSING_FAILURE, "DocprocService " + requestContext.getServiceName() + " not found."); return null; } else if (service.getExecutor().getCallStack().size() == 0) { //call stack was empty, just forward message requestContext.skip(); return null; } DocumentProcessingTask task = new DocumentProcessingTask(requestContext, this, service); submit(task); return null; }
progress = executor.process(processing); } catch (Exception e) { logProcessingFailure(processing, e);
progress = ex.process(processing); } catch (Exception e) { processingFailed(processing, processing + " failed", e);