/** * 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(); }
private DocprocExecutor getExecutor(ComponentSpecification chain) { DocprocService service = handler.getDocprocServiceRegistry().getComponent(chain); if (service == null) { throw new IllegalArgumentException("No such chain: " + chain); } return service.getExecutor(); }
/** * 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); }
@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); } } }
@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; }
DocprocExecutor ex = getExecutor(); if (ex == null) { throw new NoCallStackException();