/** * Returns whether this stack has this call (left) * * @param call * the call to check * @return true if the call is present, false otherwise */ public boolean contains(final Call call) { for (final ListIterator<Call> i = iterator(); i.hasNext();) { final Call current = i.next(); if (current == call) { return true; } } return false; }
/** * Adds an element just after the first occurence of some other element on * the stack. This can not be called during an iteration. * * @param after * the call to add this after. If this call is not present, (the * same object instance), the new processor is added as the last * element * @param processor * the processor to add * @return this for convenience */ public CallStack addAfter(final Call after, final DocumentProcessor processor) { return addAfter(after, new Call(processor, name, statistics, metric)); }
/** * Adds an element just before the first occurence of some element on the * stack. This can not be called during an iteration. * * @param before * the call to add this before. If this call is not present (the * same object instance), the new processor is added as the last * element * @param processor the processor to add * @return this for convenience */ public CallStack addBefore(final Call before, DocumentProcessor processor) { return addBefore(before, new Call(processor, name, statistics, metric)); }
/** * Creates a new named DocprocExecutor with the given CallStack. * * @param name the name of this executor * @param callStack the chain of document processors this executor shall execute on processings */ public DocprocExecutor(String name, CallStack callStack) { this.name = name; String chainDimension = name; if (name != null) { chainDimension = name.replaceAll("[^\\p{Alnum}]", "_"); docCounterName = "chain_" + name.replaceAll("[^\\p{Alnum}]", "_") + "_documents"; } else { //name is null docCounterName = "chain_" + name + "_documents"; } docCounter = new Counter(docCounterName, callStack.getStatistics(), false); this.metric = callStack.getMetric(); this.callStack = callStack; this.callStack.setName(name); this.context = this.metric.createContext(Collections.singletonMap("chain", chainDimension)); }
/** * Creates a stack (with a given name) based on a collection of document processors, which are added to the stack * in the iteration order of the collection. * * @param name the name of the stack * @param docprocs the document processors to call */ public CallStack(final String name, Collection<DocumentProcessor> docprocs, Statistics manager, Metric metric) { this(name, manager, metric); for (DocumentProcessor docproc : docprocs) { addLast(docproc); } }
private static CallStack convertToCallStack(Chain<DocumentProcessor> chain, Statistics statistics, Metric metric) { CallStack stack = new CallStack(chain.getId().stringValue(), statistics, metric); for (DocumentProcessor processor : chain.components()) { processor.getFieldMap().putAll(DocprocService.schemaMap.chainMap(chain.getId().stringValue(), processor.getId().stringValue())); stack.addLast(processor); } return stack; }
public String toString() { String previousCall = ""; if (callStack != null) { Call call = callStack.getLastPopped(); if (call != null) { previousCall = "Last call: " + call; } } if (documentOperations.size() == 1) { return "Processing of " + documentOperations.get(0) + ". " + previousCall; } else { String listString = documentOperations.toString(); if (listString.length() > 100) { listString = listString.substring(0, 99); listString += "...]"; } return "Processing of " + listString + ". " + previousCall; } }
/** * Asynchronously process the given document put or document update using the processing * chain of this service, and call the specified ProcessingEndpoint when done. * * @throws RuntimeException caused by a QueueFullException if this DocprocService has a bounded input queue and the queue is full * @throws IllegalStateException if this DocprocService is not accepting new incoming processings */ public void process(DocumentOperation documentOperation, ProcessingEndpoint endp) { addProcessing(new Processing(getName(), documentOperation, new CallStack(getCallStack()), endp)); }
/** * Returns the next call to this processor, or null if no such calls are * left */ public Call findCall(final DocumentProcessor processor) { return findCall(processor.getId()); }
/** * Push an element as the <i>next</i> element on this stack * * @return this for convenience */ public CallStack addNext(final DocumentProcessor processor) { return addNext(new Call(processor, name, statistics, metric)); }
/** * Adds multiple elements just after another given element on the stack. * This can not be called during an iteration. * * @param after * the call to add this before. If this call is not present, (the * same object instance), the new processor is added as the last * element * @param callStack * the calls to add * @return this for convenience */ public CallStack addAfter(final Call after, final CallStack callStack) { final int insertPosition = elements.indexOf(after); if (insertPosition < 0) { addLast(callStack); } else { elements.addAll(insertPosition + 1, callStack.elements); } return this; }
private static void logProcessingFailure(Processing processing, Exception exception) { //LOGGING ONLY: String errorMsg = processing + " failed at " + processing.callStack().getLastPopped(); if (exception != null) { if (exception instanceof HandledProcessingException) { errorMsg += ". Error message: " + exception.getMessage(); log.log(Level.WARNING, errorMsg); log.log(Level.FINE, "Chained exception:", exception); } else { log.log(Level.WARNING, errorMsg, exception); } } else { log.log(Level.WARNING, errorMsg); } //LOGGING OF STACK TRACE: if (exception != null) { StringWriter backtrace = new StringWriter(); exception.printStackTrace(new PrintWriter(backtrace)); log.log(LogLevel.DEBUG, "Failed to process " + processing + ": " + backtrace.toString()); } }
/** * Asynchronously process the given document operations as one unit * using the processing chain of this service, * and call the specified ProcessingEndpoint when done. * * @throws RuntimeException caused by a QueueFullException if this DocprocService has a bounded input queue and the queue is full * @throws IllegalStateException if this DocprocService is not accepting new incoming processings */ public void processDocumentOperations(List<DocumentOperation> documentOperations, ProcessingEndpoint endp) { addProcessing(Processing.createProcessingFromDocumentOperations(getName(), documentOperations, new CallStack(getCallStack()), endp)); }
/** * Removes the given call. Does nothing if the call is not present. * * @param call * the call to remove * @return this for convenience */ public CallStack remove(final Call call) { for (final ListIterator<Call> i = iterator(); i.hasNext();) { final Call current = i.next(); if (current == call) { i.remove(); } } return this; }
/** * Adds an element just before the first occurence of some other element on * the stack. This can not be called during an iteration. * * @param before * the call to add this before. If this call is not present (the * same object instance), new processor is added as the last * element * @param call the call to add * @return this for convenience */ public CallStack addBefore(final Call before, final Call call) { final int insertPosition = elements.indexOf(before); if (insertPosition < 0) { addLast(call); } else { elements.add(insertPosition, call); } return this; }
final CallStack callStack = processing.callStack(); if (callStack != null) { final Call lastPopped = callStack.getLastPopped(); if (lastPopped != null) { location = lastPopped.toString();
/** * Asynchronously process the given Processing using the processing * chain of this service, and call the specified ProcessingEndpoint when done. * * @throws RuntimeException caused by a QueueFullException if this DocprocService has a bounded input queue and the queue is full * @throws IllegalStateException if this DocprocService is not accepting new incoming processings */ public void process(Processing processing, ProcessingEndpoint endp) { processing.setServiceName(getName()); processing.setCallStack(new CallStack(getCallStack())); processing.setEndpoint(endp); addProcessing(processing); }
/** * Creates a stack from another stack (starting at the next of the given * callstack) This does a deep copy of the stack. */ public CallStack(final CallStack stackToCopy) { name = stackToCopy.name; for (final Iterator<Call> i = stackToCopy.iterator(); i.hasNext();) { final Call callToCopy = i.next(); elements.add((Call) callToCopy.clone()); } this.statistics = stackToCopy.statistics; this.metric = stackToCopy.metric; }
/** * Adds multiple elements just before the first occurence of some element on * the stack. This can not be called during an iteration. * * @param before * the call to add this before. If this call is not present (the * same object instance), the new processor is added as the last * element * @param callStack * the calls to add * @return this for convenience */ public CallStack addBefore(final Call before, final CallStack callStack) { final int insertPosition = elements.indexOf(before); if (insertPosition < 0) { addLast(callStack); } else { elements.addAll(insertPosition, callStack.elements); } return this; }