summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/filetransfer/util/HashChecker.java
diff options
context:
space:
mode:
authorSimon Rettberg2016-04-18 15:18:05 +0200
committerSimon Rettberg2016-04-18 15:18:05 +0200
commitcc70f09431deb7937e01cc6583884fb5067a2994 (patch)
treefcf7c8720a4479b09e07c82eb13f7015bb4d0533 /src/main/java/org/openslx/filetransfer/util/HashChecker.java
parentPreparations/changes for global image sync (diff)
downloadmaster-sync-shared-cc70f09431deb7937e01cc6583884fb5067a2994.tar.gz
master-sync-shared-cc70f09431deb7937e01cc6583884fb5067a2994.tar.xz
master-sync-shared-cc70f09431deb7937e01cc6583884fb5067a2994.zip
More additions for central image store
Diffstat (limited to 'src/main/java/org/openslx/filetransfer/util/HashChecker.java')
-rw-r--r--src/main/java/org/openslx/filetransfer/util/HashChecker.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/filetransfer/util/HashChecker.java b/src/main/java/org/openslx/filetransfer/util/HashChecker.java
index 5b647aa..d9db7df 100644
--- a/src/main/java/org/openslx/filetransfer/util/HashChecker.java
+++ b/src/main/java/org/openslx/filetransfer/util/HashChecker.java
@@ -75,7 +75,16 @@ public class HashChecker
}
}
- public void queue( FileChunk chunk, byte[] data, HashCheckCallback callback ) throws InterruptedException
+ /**
+ * Queue the given chunk for hashing. The chunk should be in pending state.
+ *
+ * @param chunk chunk to hash
+ * @param data binary data of this chunk
+ * @param callback callback to call when hashing is done
+ * @return true if the chunk was handled, false if the queue was full and rejected the chunk.
+ * @throws InterruptedException
+ */
+ public boolean queue( FileChunk chunk, byte[] data, HashCheckCallback callback, boolean blocking ) throws InterruptedException
{
byte[] sha1Sum = chunk.getSha1Sum();
if ( sha1Sum == null )
@@ -84,7 +93,7 @@ public class HashChecker
synchronized ( threads ) {
if ( invalid ) {
execCallback( task, HashResult.FAILURE );
- return;
+ return true;
}
if ( queue.remainingCapacity() <= 1 && threads.size() < Runtime.getRuntime().availableProcessors() ) {
try {
@@ -95,8 +104,18 @@ public class HashChecker
LOGGER.warn( "Could not create additional hash checking thread", e );
}
}
+ }
+ ChunkStatus old = chunk.getStatus();
+ chunk.setStatus( ChunkStatus.HASHING );
+ if ( blocking ) {
queue.put( task );
+ } else {
+ if ( !queue.offer( task ) ) {
+ chunk.setStatus( old );
+ return false;
+ }
}
+ return true;
}
// ############################################################# \\
@@ -171,7 +190,6 @@ public class HashChecker
this.data = data;
this.chunk = chunk;
this.callback = callback;
- chunk.setStatus( ChunkStatus.HASHING );
}
}