summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-05-09 13:58:49 +0200
committerSimon Rettberg2018-05-09 13:58:49 +0200
commitff5aef8b8688d8cdef7bbfef216475b48a4dd096 (patch)
treecd6109c6267770089b709305e3d3374d6740ba1b
parentFix CRC32 buffer race mutithread concurrent access violation usage (diff)
downloadmaster-sync-shared-ff5aef8b8688d8cdef7bbfef216475b48a4dd096.tar.gz
master-sync-shared-ff5aef8b8688d8cdef7bbfef216475b48a4dd096.tar.xz
master-sync-shared-ff5aef8b8688d8cdef7bbfef216475b48a4dd096.zip
Update TransferStatusWrapper to return actual and estimated completeness
-rw-r--r--src/main/java/org/openslx/thrifthelper/TransferStatusWrapper.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/thrifthelper/TransferStatusWrapper.java b/src/main/java/org/openslx/thrifthelper/TransferStatusWrapper.java
index 2c0cd66..bb84990 100644
--- a/src/main/java/org/openslx/thrifthelper/TransferStatusWrapper.java
+++ b/src/main/java/org/openslx/thrifthelper/TransferStatusWrapper.java
@@ -36,6 +36,33 @@ public class TransferStatusWrapper
return ((float)done / (float)blocks.length);
}
+ public static class Progress {
+ public float done;
+ public float potentiallyDone;
+ }
+
+ /**
+ * Return completeness of transfer, guaranteed and estimated.
+ * .done will be what is known to be completed and good,
+ * .potentiallyDone will be what is queued for copying and still
+ * hashing, so can be considered and optimistic estimate.
+ * Values are returned as float between 0 and 1.
+ * .done + .potentiallyDone will never be > 1.
+ * @param progress array with length >= 2
+ */
+ public void getCompleteEx(Progress progress) {
+ int done = 0, potentialDone = 0;
+ for (byte block : blocks) {
+ if (block == 0) {
+ done++;
+ } else if (block == 3 || block == 4 || block == 5) {
+ potentialDone++;
+ }
+ }
+ progress.done = ((float)done / (float)blocks.length);
+ progress.potentiallyDone = ((float)(done + potentialDone) / (float)blocks.length);
+ }
+
public float getPercentComplete() {
return getComplete() * 100f;
}