diff options
author | Nils Schwabe | 2014-07-11 15:46:18 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-11 15:46:18 +0200 |
commit | 0e2d23f82f8c564b7267c14414e38de9c71a081f (patch) | |
tree | b7a8914862e4f0423a32c5141e14f8d4f377dd9c /src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java | |
parent | Start to implement download functionallity (diff) | |
download | masterserver-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/ImageProcessor.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java index 10580a7..8e7c011 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java @@ -68,8 +68,8 @@ public class ImageProcessor String token; String filepath; String crcPath; - - List<Integer> allBlocks; + int nBlocks; + int[] allBlocks; UploadingImage image; synchronized ( uploadingImages ) { @@ -88,24 +88,21 @@ public class ImageProcessor filepath = Globals.getImageDir() + "/" + uuid + ".vmdk"; token = RandomString.generate( 100, false ); crcPath = Globals.getImageDir() + "/" + uuid + ".crc"; - int nBlocks = (int)Math.ceil( imageData.fileSize / Globals.blockSize ); - allBlocks = new ArrayList<>( nBlocks ); - for ( int i = nBlocks - 1; i >= 0; i-- ) { // fill empty list with all block numbers - allBlocks.add( i ); - } + nBlocks = (int)Math.ceil( imageData.fileSize / Globals.blockSize ); + allBlocks = new int[nBlocks]; // initalize array with all zeros which mean that this block is missing image = new UploadingImage( token, allBlocks, new Timestamp( System.currentTimeMillis() ), uuid, filepath, crcPath ); uploadingImages.put( uuid, image ); } try { - new CRCFile( crcSums, crcPath); + CRCFile.writeCrcFile( crcSums, crcPath ); } catch (IOException e) { log.error( "Could not create crc file", e ); return null; // TODO: what to do if we can not write the crc file to disk? Give object to crcscheduler? } ConnectionHandler.addConnection( token, filepath, Connection.UPLOADING ).image = image; - DbImage.insert( imageData, System.currentTimeMillis(), token, allBlocks, serverSessionId, filepath ); + DbImage.insert( imageData, System.currentTimeMillis(), token, nBlocks, serverSessionId, filepath ); imagesToCheck.add( uuid ); log.debug( "Returning UploadInfos. Client should goint to start the upload. " ); @@ -178,14 +175,19 @@ public class ImageProcessor */ private static List<Integer> getNMissingBlocks( UploadingImage image, int amount ) { - int size = image.amountOfMissingBlocks(); + int size = image.getAmountOfMissingBlocks(); if ( amount > size ) amount = size; List<Integer> result = new ArrayList<>( amount ); - for ( int i = 1; i <= amount; i++ ) { - result.add( image.removeMissingBlock( size - i ) ); + int got = 0; + for ( int i = 0; i < image.getNumberOfBlocks(); i++ ) { + if (image.needsRequest( i )) { + result.add( i ) ; + got++; + } + if (got == amount) break; } return result; @@ -220,12 +222,11 @@ public class ImageProcessor while ( iter.hasNext() ) { result.add( uploadingImages.get( iter.next() ) ); } - return result; } public static List<Integer> getRequestedBlocks( String token) { - + // for the downloader return null; } @@ -238,7 +239,7 @@ public class ImageProcessor for ( DbImage image : list ) { String token = image.token; ConnectionHandler.addConnection( token, image.imagePath, Connection.UPLOADING ); - UploadingImage infos = new UploadingImage( token, image.missingBlocks, image.timestamp, + UploadingImage infos = new UploadingImage( token, image.blockStatus, image.timestamp, image.uuid, image.imagePath, Globals.getImageDir() + "/" + image.uuid + ".crc" ); uploadingImages.put( image.uuid, infos ); } |