summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java
diff options
context:
space:
mode:
authorNils Schwabe2014-07-11 15:46:18 +0200
committerNils Schwabe2014-07-11 15:46:18 +0200
commit0e2d23f82f8c564b7267c14414e38de9c71a081f (patch)
treeb7a8914862e4f0423a32c5141e14f8d4f377dd9c /src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java
parentStart to implement download functionallity (diff)
downloadmasterserver-0e2d23f82f8c564b7267c14414e38de9c71a081f.tar.gz
masterserver-0e2d23f82f8c564b7267c14414e38de9c71a081f.tar.xz
masterserver-0e2d23f82f8c564b7267c14414e38de9c71a081f.zip
Change now saving status of blocks in array
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java98
1 files changed, 61 insertions, 37 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java
index 0e36175..27e18fd 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java
@@ -1,9 +1,6 @@
package org.openslx.imagemaster.serverconnection;
import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.log4j.Logger;
import org.openslx.imagemaster.db.DbImage;
@@ -13,57 +10,70 @@ import org.openslx.imagemaster.db.DbImage;
*/
public class UploadingImage
{
+
public static final Logger log = Logger.getLogger( UploadingImage.class );
/**
* Token for the satellite.
*/
private String token;
/**
- * The missing blocks that need to be uploaded by the satellite.
- */
- private List<Integer> missingBlocks;
- /**
- * The list of blocks that were requested but not checked
+ * The status list of the blocks.
+ * x = 0 block is missing
+ * x = 200 block arrived and is valid
+ * x > 0 block is invalid and was transmitted x times (needs request)
+ * x < 0 block is invalid and was transmitted x times (needs check)
*/
- private List<Integer> blocksToCheck = new LinkedList<>();
+ private int[] blockStatus = null;
+ public static final int valid = 200;
+ public static final int missing = 0;
private Timestamp ts; // when did the server something for the last time
private DbImage dbImage = null; // the DB representation of this image
private String uuid;
private String filename;
private String crcFilename;
- protected UploadingImage(String token, List<Integer> missingBlocks, Timestamp ts, String uuid, String filename, String crcFilename)
+ protected UploadingImage(String token, int[] initialBlockStatus, Timestamp ts, String uuid, String filename, String crcFilename)
{
this.token = token;
- this.missingBlocks = missingBlocks;
this.ts = ts;
this.uuid = uuid;
this.crcFilename = crcFilename;
+ this.blockStatus = initialBlockStatus;
}
- protected void removeBlock( int number )
+ protected void setValid( int index )
{
- this.missingBlocks.remove( number );
- dbImage.updateMissingBlocks( missingBlocks );
+ if ( blockStatus == null )
+ return;
+ blockStatus[index] = valid;
}
- protected void removeBlocks( Collection<Integer> list )
+ protected void setMissing( int index )
{
- this.missingBlocks.removeAll( list );
- dbImage.updateMissingBlocks( missingBlocks );
+ if ( blockStatus == null )
+ return;
+ blockStatus[index] = missing;
}
-
- protected void addBlockToCheck( int number )
+
+ protected void setNeedsRequest( int index )
{
- synchronized ( blocksToCheck ) {
- blocksToCheck.add( number );
- }
- log.debug( number + " added to check list..." );
+ if ( blockStatus == null )
+ return;
+ blockStatus[index] *= ( blockStatus[index] < missing ) ? -1 : 1; // switch to positive value if needed
+ }
+
+ protected void setNeedsCheck( int index )
+ {
+ if ( blockStatus == null )
+ return;
+ blockStatus[index] *= ( blockStatus[index] > missing ) ? -1 : 1; // switch to negative value if needed
}
- protected List<Integer> getNotCheckedBlocks()
+ protected void increaseTransmittedTimes( int index )
{
- return this.blocksToCheck;
+ if ( blockStatus == null || blockStatus[index] == 0 || blockStatus[index] == 200 )
+ return;
+ blockStatus[index] += ( blockStatus[index] < missing ) ? -1 : 1; // increase in both directions
}
protected String getToken()
@@ -71,9 +81,23 @@ public class UploadingImage
return this.token;
}
- protected List<Integer> getAllMissingBlocks()
+ protected boolean needsRequest( int index )
+ {
+ if ( blockStatus == null )
+ return false;
+ return ( blockStatus[index] > missing && blockStatus[index] != valid );
+ }
+
+ protected boolean needsCheck( int index )
+ {
+ if ( blockStatus == null )
+ return false;
+ return ( blockStatus[index] < missing );
+ }
+
+ protected int getNumberOfBlocks()
{
- return this.missingBlocks;
+ return blockStatus.length;
}
protected Timestamp getTimestamp()
@@ -88,26 +112,26 @@ public class UploadingImage
}
return this.dbImage;
}
-
+
protected String getFilename()
{
return this.filename;
}
-
+
protected String getCrcFilename()
{
return this.crcFilename;
}
- public int amountOfMissingBlocks()
- {
- return missingBlocks.size();
- }
-
- public int removeMissingBlock( int index )
+ public int getAmountOfMissingBlocks()
{
- synchronized ( missingBlocks ) {
- return missingBlocks.remove( index );
+ if ( blockStatus == null )
+ return 0;
+ int result = 0;
+ for ( int i : blockStatus ) {
+ if ( blockStatus[i] == missing )
+ result++;
}
+ return result;
}
}