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 missingBlocks; /** * The list of blocks that were requested but not checked */ private List 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 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 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 getNotCheckedBlocks() { return this.blocksToCheck; } protected String getToken() { return this.token; } protected List 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 ); } } }