diff options
author | Nils Schwabe | 2014-07-23 14:19:46 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-23 14:19:46 +0200 |
commit | 56512f44aa6430aeeabe5b81057d30c169fce104 (patch) | |
tree | 9572b3984147b631a652c2a8118b6678e5e80f3f /src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java | |
parent | Add that client gets error if a certain block was transmitted to many times a... (diff) | |
download | masterserver-56512f44aa6430aeeabe5b81057d30c169fce104.tar.gz masterserver-56512f44aa6430aeeabe5b81057d30c169fce104.tar.xz masterserver-56512f44aa6430aeeabe5b81057d30c169fce104.zip |
Fix some bugs while testing the connection
Change log level of thrift filetransfer to error in log4j properties
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java index dc15dae..8cbaecf 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java @@ -1,5 +1,8 @@ package org.openslx.imagemaster.serverconnection; +import java.util.ArrayList; +import java.util.List; + import org.apache.log4j.Logger; import org.openslx.imagemaster.Globals; import org.openslx.imagemaster.crcchecker.CRCFile; @@ -40,6 +43,7 @@ public class UploadingImage this.timestamp = timestamp; this.uuid = uuid; this.blockStatus = initialBlockStatus; + this.filename = filename; } protected void setValid( int index ) @@ -48,6 +52,21 @@ public class UploadingImage return; blockStatus[index] = valid; } + + protected void updateDb() + { + if ( blockStatus == null ) + return; + + List<Integer> missingBlocks = new ArrayList<>(); + + for (int block = 0; block < blockStatus.length; block++) { + if (blockStatus[block] != valid) { + missingBlocks.add( block ); + } + } + dbImage.updateMissingBlocks( missingBlocks ); + } protected void setMissing( int index ) { @@ -72,9 +91,9 @@ public class UploadingImage protected void increaseTransmittedTimes( int index ) { - if ( blockStatus == null || blockStatus[index] == 0 || blockStatus[index] == 200 ) + if ( blockStatus == null || blockStatus[index] == 200 ) return; - blockStatus[index] += ( blockStatus[index] < missing ) ? -1 : 1; // increase in both directions + blockStatus[index] += ( blockStatus[index] <= missing ) ? -1 : 1; // increase in both directions } protected int getTimesTransmitted( int index ) @@ -91,7 +110,7 @@ public class UploadingImage { if ( blockStatus == null ) return false; - return ( blockStatus[index] > missing && blockStatus[index] != valid ); + return ( ( blockStatus[index] >= missing ) && ( blockStatus[index] != valid ) ); } protected boolean needsCheck( int index ) @@ -103,6 +122,13 @@ public class UploadingImage protected int getNumberOfBlocks() { + /////////////////////////////////////////////////////////////////// + ArrayList<Integer> l = new ArrayList<Integer>( blockStatus.length ); + for ( int i : blockStatus ) { + l.add( i ); + } + log.debug( l ); + /////////////////////////////////////////////////////////////////// return blockStatus.length; } @@ -137,15 +163,34 @@ public class UploadingImage this.crcFile = crcFile; } - public int getAmountOfMissingBlocks() + public int getAmountOfBlocksNeedingRequest() { if ( blockStatus == null ) return 0; int result = 0; - for ( int i : blockStatus ) { - if ( blockStatus[i] == missing ) + for ( int i = 0; i < blockStatus.length; i++ ) { + if ( needsRequest( i ) ) result++; } return result; } + + public boolean allBlocksValid() + { + if ( blockStatus == null ) + return false; + for ( int i : blockStatus ) { + if ( i != 200 ) + return false; + } + return true; + } + + @Override + public String toString() + { + return "UUID: " + uuid + ", filename " + filename + "\nmissing blocks " + getAmountOfBlocksNeedingRequest() + + ", number of blocks " + getNumberOfBlocks() + ", token " + getToken(); + + } } |