diff options
author | Simon Rettberg | 2022-03-18 15:34:56 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-18 15:49:05 +0100 |
commit | 2b3e2992e7ea5d615531fd8c683f0f58cc456f42 (patch) | |
tree | 5b99d2da2252f70f9dfb7c244f07090fe29f5586 /dozentenmodul/src | |
parent | [client] Add even more debug spam to Upload (diff) | |
download | tutor-module-2b3e2992e7ea5d615531fd8c683f0f58cc456f42.tar.gz tutor-module-2b3e2992e7ea5d615531fd8c683f0f58cc456f42.tar.xz tutor-module-2b3e2992e7ea5d615531fd8c683f0f58cc456f42.zip |
[client] Cleanup chunk data lists when upload finished or is cancelled
Diffstat (limited to 'dozentenmodul/src')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java index 83e89302..cf593200 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java @@ -51,6 +51,8 @@ public class AsyncHashGenerator extends Thread { private final List<ByteBuffer> chunkHashes; private final List<FileChunk> chunkList; private long nextReadMsg, nextDoneMsg, nextSendingMsg; // for debug spam :-( + private boolean readingDone = false; + private boolean hashingDone = false; private volatile boolean isCanceled = false; @@ -74,6 +76,7 @@ public class AsyncHashGenerator extends Thread { this.uploadToken = token; submitHashes(false); } + cleanupIfDone(); } @Override @@ -134,6 +137,8 @@ public class AsyncHashGenerator extends Thread { } } finally { Util.safeClose(file); + readingDone = true; + cleanupIfDone(); } } @@ -219,6 +224,26 @@ public class AsyncHashGenerator extends Thread { isCanceled = true; } } + if (wasLastChunk) { + hashingDone = true; + cleanupIfDone(); + } + } + + /** + * Drop references to all the chunk metadata - in case someone is still holding + * a reference to this class, at least we will not prevent this stuff from being + * garbage collected. + */ + private void cleanupIfDone() { + if (uploadToken == null && !isCanceled) + return; + if (!readingDone) + return; + if (!hashingDone && !isCanceled) + return; + chunkHashes.clear(); + chunkList.clear(); } /** |