summaryrefslogtreecommitdiffstats
path: root/documentapi
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-10-16 22:13:35 +0200
committerJon Bratseth <bratseth@oath.com>2018-10-16 22:13:35 +0200
commit927eb12cf02cfc02e91f6e929300f523ae8887fc (patch)
tree88ba2a2051ebe14dce79fd57e3f13ae9a98905b6 /documentapi
parent16c10f396298967a5d144518227f2e36bfa80eb2 (diff)
Prepare for removal
Diffstat (limited to 'documentapi')
-rw-r--r--documentapi/src/main/java/com/yahoo/documentapi/ProgressToken.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/documentapi/src/main/java/com/yahoo/documentapi/ProgressToken.java b/documentapi/src/main/java/com/yahoo/documentapi/ProgressToken.java
index e9d34fcddea..f5701802a84 100644
--- a/documentapi/src/main/java/com/yahoo/documentapi/ProgressToken.java
+++ b/documentapi/src/main/java/com/yahoo/documentapi/ProgressToken.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;
+import java.util.Base64;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@@ -16,8 +17,8 @@ import com.yahoo.vespa.objects.Serializer;
* Token to use to keep track of progress for visiting. Can be used to resume
* visiting if visiting has been aborted for any reason.
*
- * @author <a href="mailto:thomasg@yahoo-inc.com">Thomas Gundersen</a>
- * @author <a href="mailto:vekterli@yahoo-inc.com">Tor Brede Vekterli</a>
+ * @author Thomas Gundersen
+ * @author vekterli
*/
public class ProgressToken {
@@ -247,6 +248,24 @@ public class ProgressToken {
return ret;
}
+ /** Returns a string (base64) encoding of the serial form of this token */
+ public String serializeToString() {
+ return Base64.getUrlEncoder().encodeToString(serialize());
+ }
+
+ public static ProgressToken fromSerializedString(String serializedString) {
+ byte[] serialized;
+ try {
+ serialized = Base64.getUrlDecoder().decode(serializedString);
+ } catch (IllegalArgumentException e) {
+ // Legacy visitor tokens were encoded with MIME Base64 which may fail decoding as URL-safe.
+ // Try again with MIME decoder to avoid breaking upgrade scenarios.
+ // TODO(vekterli): remove once this is no longer a risk.
+ serialized = Base64.getMimeDecoder().decode(serializedString);
+ }
+ return new ProgressToken(serialized);
+ }
+
public void addFailedBucket(BucketId superbucket, BucketId progress, String errorMsg) {
BucketId existing = failedBuckets.put(superbucket, progress);
if (existing != null) {