summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java
new file mode 100644
index 00000000000..89c2ecc8ace
--- /dev/null
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/DocumentSendInfo.java
@@ -0,0 +1,72 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.http.client.core.operationProcessor;
+
+import com.yahoo.vespa.http.client.Result;
+import com.yahoo.vespa.http.client.core.Document;
+import com.yahoo.vespa.http.client.core.api.ResultImpl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Keeps an overview of what is sent and what is received for an operation.
+ * This class is NOT thread-safe by design.
+ */
+class DocumentSendInfo {
+ private final Document document;
+ private final Map<Integer, Result.Detail> detailByClusterId = new HashMap<>();
+ // This is lazily populated as normal cases does not require retries.
+ private Map<Integer, Integer> attemptedRetriesByClusterId = null;
+ private final StringBuilder localTrace;
+
+ DocumentSendInfo(Document document, boolean traceThisDoc) {
+ this.document = document;
+ localTrace = traceThisDoc
+ ? new StringBuilder("\n" + document.createTimeMillis() + " Trace starting " + "\n")
+ : null;
+ }
+
+ boolean addIfNotAlreadyThere(Result.Detail detail, int clusterId) {
+ if (detailByClusterId.containsKey(clusterId)) {
+ if (localTrace != null) {
+ localTrace.append(System.currentTimeMillis() + " Got duplicate detail, ignoring this: "
+ + detail.toString() + "\n");
+ }
+ return false;
+ }
+ if (localTrace != null) {
+ localTrace.append(System.currentTimeMillis() + " Got detail: " + detail.toString() + "\n");
+ }
+ detailByClusterId.put(clusterId, detail);
+ return true;
+ }
+
+ int detailCount() {
+ return detailByClusterId.size();
+ }
+
+ public Result createResult() {
+ return new ResultImpl(document, detailByClusterId.values(), localTrace);
+ }
+
+ int incRetries(int clusterId, Result.Detail detail) {
+ if (attemptedRetriesByClusterId == null) {
+ attemptedRetriesByClusterId = new HashMap<>();
+ }
+ int retries = 0;
+ if (attemptedRetriesByClusterId.containsKey(clusterId)) {
+ retries = attemptedRetriesByClusterId.get(clusterId);
+ }
+ retries++;
+ attemptedRetriesByClusterId.put(clusterId, retries);
+ if (localTrace != null) {
+ localTrace.append(System.currentTimeMillis() + " Asked about retrying for cluster ID "
+ + clusterId + ", number of retries is " + retries + " Detail:\n" + detail.toString());
+ }
+ return retries;
+ }
+
+ Document getDocument() {
+ return document;
+ }
+} \ No newline at end of file