diff options
author | Nils Schwabe | 2014-07-10 16:08:36 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-10 16:08:36 +0200 |
commit | c89abbfa830876b7298eb96896a642bc74589651 (patch) | |
tree | ee3b0707be612d9147d23632713c61c52c6d27be /src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java | |
parent | Remove unintentionally added f3 docs (diff) | |
download | masterserver-c89abbfa830876b7298eb96896a642bc74589651.tar.gz masterserver-c89abbfa830876b7298eb96896a642bc74589651.tar.xz masterserver-c89abbfa830876b7298eb96896a642bc74589651.zip |
Add some better thread synchonization
Restructure some classes
Fix small connection issues
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java new file mode 100644 index 0000000..e6acb78 --- /dev/null +++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java @@ -0,0 +1,114 @@ +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; + +/** + * Helper class for ImageProcessor to save some infos about the images in the process list. + */ +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 + */ + private List<Integer> blocksToCheck = new LinkedList<>(); + 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) + { + this.token = token; + this.missingBlocks = missingBlocks; + this.ts = ts; + this.uuid = uuid; + this.crcFilename = crcFilename; + log.debug(missingBlocks); + } + + protected void removeBlock( int number ) + { + this.missingBlocks.remove( number ); + dbImage.updateMissingBlocks( missingBlocks ); + } + + protected void removeBlocks( Collection<Integer> list ) + { + this.missingBlocks.removeAll( list ); + dbImage.updateMissingBlocks( missingBlocks ); + } + + protected void addBlockToCheck( int number ) + { + synchronized ( blocksToCheck ) { + blocksToCheck.add( number ); + } + log.debug( number + " added to check list..." ); + } + + protected List<Integer> getNotCheckedBlocks() + { + return this.blocksToCheck; + } + + protected String getToken() + { + return this.token; + } + + protected List<Integer> getAllMissingBlocks() + { + return this.missingBlocks; + } + + protected Timestamp getTimestamp() + { + return this.ts; + } + + protected DbImage getDbImage() + { + if ( dbImage == null ) { + dbImage = DbImage.getImageByUUID( this.uuid ); + } + 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 ) + { + synchronized ( missingBlocks ) { + return missingBlocks.remove( index ); + } + } +} |