diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-02-02 13:40:12 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-02-02 13:40:12 +0100 |
commit | 399034959b9665b90c5de6c9d9fbf5868dd564e0 (patch) | |
tree | c231edd2f55d4476a3e514d950f289636530b6b1 /docproc | |
parent | 6c1d5b3cc3002c832ea1474d80a1b9e2001f1516 (diff) |
No functional changes
Diffstat (limited to 'docproc')
6 files changed, 61 insertions, 48 deletions
diff --git a/docproc/src/main/java/com/yahoo/docproc/DocprocService.java b/docproc/src/main/java/com/yahoo/docproc/DocprocService.java index 32f28ba1294..ae798028082 100644 --- a/docproc/src/main/java/com/yahoo/docproc/DocprocService.java +++ b/docproc/src/main/java/com/yahoo/docproc/DocprocService.java @@ -30,10 +30,10 @@ import java.util.logging.Logger; * * @author bratseth */ -//TODO Vespa 8 This class and a lot of other in this package should not be part of PublicAPI +//TODO: Vespa 8: This class and a lot of other in this package should not be part of PublicAPI public class DocprocService extends AbstractComponent { - private static Logger log = Logger.getLogger(DocprocService.class.getName()); + private static final Logger log = Logger.getLogger(DocprocService.class.getName()); private volatile DocprocExecutor executor; /** The processings currently in progress at this service */ @@ -43,7 +43,7 @@ public class DocprocService extends AbstractComponent { private boolean inService = false; /** The current state of this service */ private boolean acceptingNewProcessings = true; - public static SchemaMap schemaMap = new SchemaMap(); + public static final SchemaMap schemaMap = new SchemaMap(); private DocumentTypeManager documentTypeManager = null; private DocprocService(ComponentId id, int numThreads) { diff --git a/docproc/src/main/java/com/yahoo/docproc/DocumentProcessor.java b/docproc/src/main/java/com/yahoo/docproc/DocumentProcessor.java index 934e1a281e5..877ecf52789 100644 --- a/docproc/src/main/java/com/yahoo/docproc/DocumentProcessor.java +++ b/docproc/src/main/java/com/yahoo/docproc/DocumentProcessor.java @@ -48,10 +48,10 @@ public abstract class DocumentProcessor extends ChainedComponent { private Map<Pair<String,String>, String> fieldMap = new HashMap<>(); /** For a doc type, the actual field name mapping to do */ - // TODO how to flush this when reconfig of schemamapping? Must solve - private Map<String, Map<String, String>> docMapCache = new HashMap<>(); + // TODO: How to flush this when reconfig of schemamapping? + private final Map<String, Map<String, String>> docMapCache = new HashMap<>(); - final boolean hasAnnotations; + private final boolean hasAnnotations; public DocumentProcessor() { hasAnnotations = getClass().getAnnotation(Accesses.class) != null; @@ -70,6 +70,34 @@ public abstract class DocumentProcessor extends ChainedComponent { */ public abstract Progress process(Processing processing); + /** Sets the schema map for field names */ + public void setFieldMap(Map<Pair<String, String>, String> fieldMap) { + this.fieldMap = fieldMap; + + } + + /** Schema map for field names (doctype,from)→to */ + public Map<Pair<String, String>, String> getFieldMap() { + return fieldMap; + } + + public Map<String, String> getDocMap(String docType) { + Map<String, String> cached = docMapCache.get(docType); + if (cached!=null) { + return cached; + } + Map<String, String> ret = new HashMap<>(); + for (Entry<Pair<String, String>, String> e : fieldMap.entrySet()) { + // Remember to include tuple if doctype is unset in mapping + if (docType.equals(e.getKey().getFirst()) || e.getKey().getFirst()==null || "".equals(e.getKey().getFirst())) { + ret.put(e.getKey().getSecond(), e.getValue()); + } + } + docMapCache.put(docType, ret); + return ret; + } + + @Override public String toString() { return "processor " + getId().stringValue(); } @@ -99,7 +127,7 @@ public abstract class DocumentProcessor extends ChainedComponent { */ public static final Progress PERMANENT_FAILURE = new Progress("permanent_failure"); - private String name; + private final String name; private Optional<String> reason = Optional.empty(); @@ -120,6 +148,7 @@ public abstract class DocumentProcessor extends ChainedComponent { return new Progress(this.name, reason); } + @Override public String toString() { return name; } @@ -128,16 +157,20 @@ public abstract class DocumentProcessor extends ChainedComponent { return reason; } + @Override public boolean equals(Object object) { return object instanceof Progress && ((Progress) object).name.equals(this.name); } + @Override public int hashCode() { return name.hashCode(); } + } public static final class LaterProgress extends Progress { + private final long delay; public static final long DEFAULT_LATER_DELAY = 20; //ms @@ -153,33 +186,7 @@ public abstract class DocumentProcessor extends ChainedComponent { public long getDelay() { return delay; } - } - - /** Sets the schema map for field names */ - public void setFieldMap(Map<Pair<String, String>, String> fieldMap) { - this.fieldMap = fieldMap; - - } - /** Schema map for field names (doctype,from)→to */ - public Map<Pair<String, String>, String> getFieldMap() { - return fieldMap; - } - - public Map<String, String> getDocMap(String docType) { - Map<String, String> cached = docMapCache.get(docType); - if (cached!=null) { - return cached; - } - Map<String, String> ret = new HashMap<>(); - for (Entry<Pair<String, String>, String> e : fieldMap.entrySet()) { - // Remember to include tuple if doctype is unset in mapping - if (docType.equals(e.getKey().getFirst()) || e.getKey().getFirst()==null || "".equals(e.getKey().getFirst())) { - ret.put(e.getKey().getSecond(), e.getValue()); - } - } - docMapCache.put(docType, ret); - return ret; } } diff --git a/docproc/src/main/java/com/yahoo/docproc/Processing.java b/docproc/src/main/java/com/yahoo/docproc/Processing.java index d2583fc5a6d..616ad3c9241 100644 --- a/docproc/src/main/java/com/yahoo/docproc/Processing.java +++ b/docproc/src/main/java/com/yahoo/docproc/Processing.java @@ -20,23 +20,23 @@ import java.util.Map; */ public class Processing { - /** The name of the service which owns this processing. Null is the same as "default" */ + /** The name of the service which owns this processing. Null is the same as "default". */ private String service = null; - /** The processors to call the next work is done on this processing */ + /** The processors to call the next work is done on this processing. */ private CallStack callStack = null; - /** The collection of documents or document updates processed by this. This is never null */ + /** The collection of documents or document updates processed by this. This is never null. */ private final List<DocumentOperation> documentOperations; /** * Documents or document updates which should be added to <code>documents</code> before * the next access, or null if documents or document updates have never been added to - * this processing + * this processing. */ private List<DocumentOperation> documentsToAdd = null; - /** The processing context variables */ + /** The processing context variables. */ private Map<String, Object> context = null; /** The endpoint of this processing. */ @@ -113,6 +113,7 @@ public class Processing { } /** + * Creates a Processing from a list of operations. * * @param service the unique name of the service processing this * @param documentsAndUpdates the document operation list. This <b>transfers ownership</b> of this list @@ -121,7 +122,9 @@ public class Processing { * This <b>transfers ownership</b> of this structure * to this class. The caller <i>must not</i> modify it */ - public static Processing createProcessingFromDocumentOperations(String service, List<DocumentOperation> documentsAndUpdates, CallStack callStack) { + public static Processing createProcessingFromDocumentOperations(String service, + List<DocumentOperation> documentsAndUpdates, + CallStack callStack) { return new Processing(service, documentsAndUpdates, callStack, null, false); } @@ -245,6 +248,15 @@ public class Processing { this.callStack = callStack; } + List<DocumentOperation> getOnceOperationsToBeProcessed() { + if (operationsGotten) + return Collections.emptyList(); + + operationsGotten = true; + return getDocumentOperations(); + } + + @Override public String toString() { String previousCall = ""; if (callStack != null) { @@ -266,11 +278,4 @@ public class Processing { } } - List<DocumentOperation> getOnceOperationsToBeProcessed() { - if (operationsGotten) - return Collections.emptyList(); - - operationsGotten = true; - return getDocumentOperations(); - } } diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java index acbedaf1156..2affcf12809 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java @@ -161,7 +161,7 @@ public class DocumentProcessingHandler extends AbstractRequestHandler { String serviceName = requestContext.getServiceName(); DocprocService service = docprocServiceRegistry.getComponent(serviceName); - //No need to enqueue a task if the docproc chain is empty, just forward requestContext + // No need to enqueue a task if the docproc chain is empty, just forward requestContext if (service == null) { log.log(Level.SEVERE, "DocprocService for session '" + serviceName + "' not found, returning request '" + requestContext + "'."); diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java index 146cd9cb988..655703d10ee 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java @@ -32,7 +32,7 @@ public class DocumentProcessingTask implements Runnable { private final List<Processing> processingsDone = new ArrayList<>(); private final DocumentProcessingHandler docprocHandler; - private RequestContext requestContext; + private final RequestContext requestContext; private final DocprocService service; private final ThreadPoolExecutor executor; diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java index 910d4b7961b..a17be4de9a5 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java @@ -107,4 +107,5 @@ class ProcessingFactory { processing.setVariable("timeout", message.getTimeRemaining()); return processing; } + } |