diff options
Diffstat (limited to 'src')
3 files changed, 77 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/filetransfer/Transfer.java b/src/main/java/org/openslx/filetransfer/Transfer.java index 4502622..bc7837f 100644 --- a/src/main/java/org/openslx/filetransfer/Transfer.java +++ b/src/main/java/org/openslx/filetransfer/Transfer.java @@ -72,7 +72,6 @@ public abstract class Transfer protected boolean sendRange( long startOffset, long endOffset ) { try { - log.debug( "Sending range: " + startOffset + " to " + endOffset ); sendKeyValuePair( "RANGE", startOffset + ":" + endOffset ); } catch ( IOException e ) { e.printStackTrace(); diff --git a/src/main/java/org/openslx/filetransfer/util/ChunkList.java b/src/main/java/org/openslx/filetransfer/util/ChunkList.java index d38c15d..4a55278 100644 --- a/src/main/java/org/openslx/filetransfer/util/ChunkList.java +++ b/src/main/java/org/openslx/filetransfer/util/ChunkList.java @@ -73,11 +73,12 @@ public class ChunkList if ( missingChunks.isEmpty() && pendingChunks.isEmpty() ) return null; if ( missingChunks.isEmpty() ) { - this.wait( 3000 ); + this.wait( 6000 ); if ( missingChunks.isEmpty() ) return null; } FileChunk c = missingChunks.remove( 0 ); + c.setStatus( ChunkStatus.UPLOADING ); pendingChunks.add( c ); return c; } @@ -130,7 +131,7 @@ public class ChunkList public synchronized void markSuccessful( FileChunk c ) { if ( !pendingChunks.remove( c ) ) { - LOGGER.warn( "Inconsistent state: markTransferred called for Chunk " + c.toString() + LOGGER.warn( "Inconsistent state: markSuccessful called for Chunk " + c.toString() + ", but chunk is not marked as currently transferring!" ); return; } @@ -161,9 +162,76 @@ public class ChunkList return c.incFailed(); } + /** + * Check if all blocks in this list are marked as successfully transfered. If a complete chunk is + * marked as "hashing", or if there are some complete chunks without a sha1sum and some with a + * sha1sum, the transfer is considered incomplete. + * + * @return true iff transfer is complete + */ public synchronized boolean isComplete() { - return missingChunks.isEmpty() && pendingChunks.isEmpty(); + if ( !missingChunks.isEmpty() || !pendingChunks.isEmpty() ) + return false; + boolean sawWithHash = false; + for ( FileChunk chunk : completeChunks ) { + if ( chunk.status == ChunkStatus.HASHING ) + return false; + if ( chunk.sha1sum != null ) { + sawWithHash = true; + } else if ( chunk.sha1sum == null && sawWithHash ) { + return false; + } + } + return true; + } + + @Override + public synchronized String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( '{' ); + for ( FileChunk chunk : allChunks ) { + sb.append( '[' ); + sb.append( chunk.getChunkIndex() ); + if ( chunk.getSha1Sum() != null ) + sb.append( '+' ); + //// + switch ( chunk.status ) { + case COMPETE: + sb.append( 'C' ); + break; + case COPYING: + sb.append( '>' ); + break; + case HASHING: + sb.append( 'H' ); + break; + case MISSING: + sb.append( 'M' ); + break; + case QUEUED_FOR_COPY: + sb.append( 'Q' ); + break; + case UPLOADING: + sb.append( 'P' ); + break; + default: + sb.append( '?' ); + break; + + } + sb.append( '|' ); //////////// + if ( missingChunks.contains( chunk ) ) + sb.append( 'M' ); + if ( pendingChunks.contains( chunk ) ) + sb.append( 'P' ); + if ( completeChunks.contains( chunk ) ) + sb.append( 'C' ); + sb.append( ']' ); + } + sb.append( '}' ); + return sb.toString(); } } diff --git a/src/main/java/org/openslx/filetransfer/util/FileChunk.java b/src/main/java/org/openslx/filetransfer/util/FileChunk.java index 0204e00..36892fb 100644 --- a/src/main/java/org/openslx/filetransfer/util/FileChunk.java +++ b/src/main/java/org/openslx/filetransfer/util/FileChunk.java @@ -1,6 +1,5 @@ package org.openslx.filetransfer.util; -import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -84,7 +83,7 @@ public class FileChunk return (int) ( ( fileSize + CHUNK_SIZE - 1 ) / CHUNK_SIZE ); } - public static void createChunkList( Collection<FileChunk> list, long fileSize, List<byte[]> sha1Sums ) + public static void createChunkList( List<FileChunk> list, long fileSize, List<byte[]> sha1Sums ) { if ( fileSize < 0 ) throw new IllegalArgumentException( "fileSize cannot be negative" ); @@ -107,4 +106,9 @@ public class FileChunk offset = end; } } + + public int getFailCount() + { + return failCount; + } } |