private static JSONArray renderCalls(Iterator<Call> components) { JSONArray ret = new JSONArray(); while (components.hasNext()) { Call c = components.next(); JSONObject jc = renderComponent(c.getDocumentProcessor(), c.getDocumentProcessor().getId()); ret.put(jc); } return ret; }
/** * 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)); }
/** * 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; }
private void schemaMapProcessing(Processing processing) { final List<DocumentOperation> documentOperations = processing.getDocumentOperations(); for (int i = 0; i < documentOperations.size(); i++) { DocumentOperation op = documentOperations.get(i); if (op instanceof DocumentPut) { documentOperations.set(i, configDoc(processor, (DocumentPut) op)); } else if (op instanceof DocumentUpdate) { documentOperations.set(i, configDocUpd(processor, (DocumentUpdate) op)); } } }
/** * Call the DocumentProcessor of this call. * * @param processing the Processing object to use * @return the progress of the DocumentProcessor that was called */ public DocumentProcessor.Progress call(Processing processing) { try { int numDocs = processing.getDocumentOperations().size(); schemaMapProcessing(processing); long startTime = SystemTimer.INSTANCE.milliTime(); DocumentProcessor.Progress retval = processor.process(processing); incrementProcTime(SystemTimer.INSTANCE.milliTime() - startTime); incrementDocs(numDocs); return retval; } finally { unwrapSchemaMapping(processing); } }
private void logProgress(Processing processing, DocumentProcessor.Progress progress, Call call) { StringBuilder message = new StringBuilder(); boolean first = true; message.append(call.getDocumentProcessorId()).append(" of class ") .append(call.getDocumentProcessor().getClass().getSimpleName()).append(" returned ").append(progress) .append(" for the documents: ["); for (DocumentOperation op : processing.getDocumentOperations()) { if (first) { first = false; } else { message.append(", "); } if (op instanceof DocumentPut) { message.append(Utf8.toString(JsonWriter.toByteArray(((DocumentPut) op).getDocument()))); } else { message.append(op.toString()); } } message.append("]"); log.log(LogLevel.SPAM, message.toString()); }
public String toString() { return "call to class " + processor.getClass().getName() + " (id: " + getDocumentProcessorId() + ")"; }
progress = call.call(processing);
public Call(DocumentProcessor processor, String chainName, Statistics manager, Metric metric) { this.processor = processor; if (chainName == null) chainName = ""; chainName = chainName.replaceAll("[^\\p{Alnum}]", "_"); docCounterName = "docprocessor_" + chainName + "_" + getDocumentProcessorId().stringValue().replaceAll("[^\\p{Alnum}]", "_") + "_documents"; procTimeCounterName = "docprocessor_" + chainName + "_" + getDocumentProcessorId().stringValue().replaceAll("[^\\p{Alnum}]", "_") + "_proctime"; docCounter = new Counter(docCounterName, manager, false); procTimeCounter = new Counter(procTimeCounterName, manager, false, null, true); this.metric = metric; }
/** * Adds an element as the <i>last</i> element on this stack * * @return this for convenience */ public CallStack addLast(final DocumentProcessor processor) { return addLast(new Call(processor, name, statistics, metric)); }
/** * Returns the next call to this processor id, or null if no such calls are * left */ public Call findCall(final ComponentId processorId) { for (final Iterator<Call> i = iterator(); i.hasNext();) { final Call call = i.next(); if (call.getDocumentProcessorId().equals(processorId)) { return call; } } return null; }
/** * 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)); }
/** * 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)); }