diff options
author | Nils Schwabe | 2014-07-07 14:36:22 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-07 14:36:22 +0200 |
commit | bf8913eb78d7f1a461ade9cc3696e0f9ce253e25 (patch) | |
tree | 7e694e7f95a6422138a8904a4c69cfab5597c169 /src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java | |
parent | Begin to implement crc scheduler... (not working) (diff) | |
download | masterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.tar.gz masterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.tar.xz masterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.zip |
Add port to up- and download thingis
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java index 05c094b..94d55ed 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java @@ -66,10 +66,11 @@ public class ImageProcessor List<Integer> missing = getMissingBlocks( uuid, AMOUNT ); if ( missing.isEmpty() ) { uploadDone( uuid ); - return new UploadInfos( null, missing ); + return new UploadInfos( null, 0, missing ); } uploadingImages.get( uuid ).addNotCheckedBlocks( missing ); - return new UploadInfos( uploadingImages.get( uuid ).getToken(), missing ); + UploadingImageInfos image = uploadingImages.get( uuid ); + return new UploadInfos( image.getToken(), image.getPort(), missing ); } // insert new image and start listener @@ -81,11 +82,11 @@ public class ImageProcessor } String token = RandomString.generate( 100, false ); String filepath = Globals.getImageDir() + "/" + uuid + ".vmdk"; - ConnectionHandler.addConnection( token, filepath, ConnectionData.UPLOADING ); + int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.UPLOADING ); // TODO: proper synchronization, interface is multi threaded. // should synchronize operations on the map (use concurrent map) and then synchronize on the uploading image // when handing the missing blocks etc... - uploadingImages.put( uuid, new UploadingImageInfos( token, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid, filepath, "CRCFILE" ) ); + uploadingImages.put( uuid, new UploadingImageInfos( token, port, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid, filepath, "CRCFILE" ) ); DbImage.insert( imageData, System.currentTimeMillis(), token, allBlocks, serverSessionId, filepath ); imagesToCheck.add( uuid ); @@ -95,7 +96,7 @@ public class ImageProcessor uploadDone( uuid ); } uploadingImages.get( uuid ).addNotCheckedBlocks( missing ); - return new UploadInfos( token, missing ); + return new UploadInfos( token, port, missing ); } } @@ -117,17 +118,17 @@ public class ImageProcessor // client was downloading this image // update the requested blocks client.requestBlocks( uuid, requestedBlocks ); - return new DownloadInfos( client.getToken( uuid ) ); + return new DownloadInfos( client.getToken( uuid ), client.getPort( uuid ) ); } // server was downloading another image and now gets a new connection for this new download String token = RandomString.generate( 100, false ); String filepath = DbImage.getImageByUUID( uuid ).imagePath; - client.addDownload( uuid, requestedBlocks, token ); + int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING ); + client.addDownload( uuid, port, requestedBlocks, token ); downloadingClients.put( serverSessionId, client ); - ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING ); - return new DownloadInfos( token ); + return new DownloadInfos( token, port ); } // insert new client and start listener @@ -135,11 +136,11 @@ public class ImageProcessor DownloadingClientInfos client = new DownloadingClientInfos(); String token = RandomString.generate( 100, false ); String filepath = DbImage.getImageByUUID( uuid ).imagePath; - client.addDownload( uuid, requestedBlocks, token ); + int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING ); + client.addDownload( uuid, port, requestedBlocks, token ); downloadingClients.put( serverSessionId, client ); - ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING ); - return new DownloadInfos( token ); + return new DownloadInfos( token, port ); } } @@ -222,8 +223,8 @@ public class ImageProcessor List<DbImage> list = DbImage.getUploadingImages(); for ( DbImage image : list ) { String token = image.token; - ConnectionHandler.addConnection( token, image.imagePath, ConnectionData.UPLOADING ); - UploadingImageInfos infos = new UploadingImageInfos( token, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid, image.imagePath, "CRCFILE" ); + int port = ConnectionHandler.addConnection( token, image.imagePath, ConnectionData.UPLOADING ); + UploadingImageInfos infos = new UploadingImageInfos( token, port, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid, image.imagePath, "CRCFILE" ); uploadingImages.put( image.uuid, infos ); } log.info( "Added " + list.size() + " pending upload(s) to process list again." ); |