summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/fileserv/ChunkList.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-11 18:40:49 +0200
committerSimon Rettberg2015-06-11 18:40:49 +0200
commite0005ceecfd9281230c4add7575b18ee88307774 (patch)
treea73bbcfc213df478c701aac120ae2b7c6e52bb1b /dozentenmodulserver/src/main/java/fileserv/ChunkList.java
parent[server] db stuff, new interface, ... (diff)
downloadtutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.gz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.xz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.zip
[server] On mah way (lots of restructuring, some early db classes, sql dump of current schema)
Diffstat (limited to 'dozentenmodulserver/src/main/java/fileserv/ChunkList.java')
-rw-r--r--dozentenmodulserver/src/main/java/fileserv/ChunkList.java78
1 files changed, 0 insertions, 78 deletions
diff --git a/dozentenmodulserver/src/main/java/fileserv/ChunkList.java b/dozentenmodulserver/src/main/java/fileserv/ChunkList.java
deleted file mode 100644
index 95b3e1fa..00000000
--- a/dozentenmodulserver/src/main/java/fileserv/ChunkList.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package fileserv;
-
-import java.nio.ByteBuffer;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-public class ChunkList {
-
- private static final Logger LOGGER = Logger.getLogger(ChunkList.class);
-
- /**
- * Chunks that are missing from the file
- */
- private final List<FileChunk> missingChunks = new LinkedList<>();
-
- /**
- * Chunks that are currently being uploaded or hash-checked
- */
- private final List<FileChunk> pendingChunks = new LinkedList<>();
-
- // Do we need to keep valid chunks, or chunks that failed too many times?
-
- public ChunkList(long fileSize, List<ByteBuffer> sha1Sums) {
- FileChunk.createChunkList(missingChunks, fileSize, sha1Sums);
- }
-
- /**
- * Get a missing chunk, marking it pending.
- *
- * @return chunk marked as missing
- */
- public synchronized FileChunk getMissing() {
- if (missingChunks.isEmpty())
- return null;
- FileChunk c = missingChunks.remove(0);
- pendingChunks.add(c);
- return c;
- }
-
- /**
- * Mark a chunk currently transferring as successfully transfered.
- *
- * @param c The chunk in question
- */
- public synchronized void markSuccessful(FileChunk c) {
- if (!pendingChunks.remove(c)) {
- LOGGER.warn("Inconsistent state: markTransferred called for Chunk " + c.toString()
- + ", but chunk is not marked as currently transferring!");
- return;
- }
- }
-
- /**
- * Mark a chunk currently transferring or being hash checked as failed
- * transfer. This increases its fail count and re-adds it to the list of
- * missing chunks.
- *
- * @param c The chunk in question
- * @return Number of times transfer of this chunk failed
- */
- public synchronized int markFailed(FileChunk c) {
- if (!pendingChunks.remove(c)) {
- LOGGER.warn("Inconsistent state: markTransferred called for Chunk " + c.toString()
- + ", but chunk is not marked as currently transferring!");
- return -1;
- }
- // Add as first element so it will be re-transmitted immediately
- missingChunks.add(0, c);
- return c.incFailed();
- }
-
- public synchronized boolean isComplete() {
- return missingChunks.isEmpty() && pendingChunks.isEmpty();
- }
-
-}