diff options
-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(); } /** |