diff options
author | Nils Schwabe | 2014-07-29 15:56:57 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-29 15:56:57 +0200 |
commit | 9c73fdd6812c3c179de0552a0fc568cb380023a0 (patch) | |
tree | 2f7de4f18a3c3d966d8fb3a6e508bb187082f923 /src/main/java/org/openslx/imagemaster/serverconnection | |
parent | Move scheduling interval to config and some more todos (diff) | |
download | masterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.tar.gz masterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.tar.xz masterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.zip |
Change some classes / methods to fit camelCase
Remove some ridiculous stuff
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection')
3 files changed, 17 insertions, 91 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java b/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java deleted file mode 100644 index f990f4e..0000000 --- a/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.openslx.imagemaster.serverconnection; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - -import org.apache.log4j.Logger; -import org.openslx.imagemaster.crcchecker.CRCChecker; - -/** - * Class to schedule crc checks. - */ -public class CRCScheduler extends TimerTask -{ - - private static Logger log = Logger.getLogger( CRCScheduler.class ); - - @Override - public void run() - { - log.debug( "Starting checks..." ); - List<UploadingImage> list = ImageProcessor.getImagesToCheck(); - log.debug( list ); - Iterator<UploadingImage> iter = list.iterator(); - while ( iter.hasNext() ) { - UploadingImage image = iter.next(); - log.debug( "Checking blocks of " + image.getDbImage().imageName ); - CRCChecker crcChecker = new CRCChecker( image.getImageFile(), image.getCrcFile() ); - log.debug( "CRCFile is valid: " + crcChecker.hasValidCrcFile() ); - if ( !crcChecker.hasValidCrcFile() ) { - image.setCrcFile( null ); // set crc file to null, so that the image processor will try to write it again. - crcChecker.done(); - continue; - } - for ( int block = 0; block < image.getNumberOfBlocks(); block++ ) { - if ( image.needsCheck( block ) ) { - try { - if ( crcChecker.checkBlock( block ) ) { - image.setValid( block ); - log.debug( block + " was valid" ); - } else { - image.setNeedsRequest( block ); - log.debug( block + " was NOT valid" ); - } - } catch ( IOException e ) { - if ( e.getMessage().equalsIgnoreCase( "crc" ) ) { - image.setCrcFile( null ); // set crc file to null, so that the imageprocessor will try to write it again. - image.updateDb(); - crcChecker.done(); - break; - } else { - // could not read image file - log.error( "Could not read from image file on disk. Pleas contact the server administrator. Image: '" + image.getImageFile().toString() + "'" ); - } - } - } - } - image.updateDb(); // writes valid blocks to database - crcChecker.done(); // closes image file - } - log.debug( "... done" ); - } - - public static void startScheduling() - { - Timer timer = new Timer( "CRCScheduler" ); - - // start now and fire every 60 s - timer.schedule( new CRCScheduler(), 0, 60000L ); - } - -} diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java index ce89acd..a738259 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java @@ -11,7 +11,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.openslx.imagemaster.Globals; -import org.openslx.imagemaster.crcchecker.CRCFile; +import org.openslx.imagemaster.crcchecker.CrcFile; import org.openslx.imagemaster.db.DbImage; import org.openslx.imagemaster.db.DbUser; import org.openslx.imagemaster.thrift.iface.DownloadInfos; @@ -83,7 +83,7 @@ public class ImageProcessor DbImage i; boolean isUpdate = false; - if ( ( i = DbImage.getImageByUUID( imageData.uuid ) ) != null ) { + if ( ( i = DbImage.getImageByUuid( imageData.uuid ) ) != null ) { // image is already available // is the client updating?? if ( imageData.imageVersion <= i.imageVersion ) { @@ -107,13 +107,13 @@ public class ImageProcessor // check if image is already uploading if ( ( image = uploadingImages.get( uuid ) ) != null ) { if ( image.getCrcFile() == null ) { - CRCFile crcFile; + CrcFile crcFile; try { // try to write crc file ... - crcFile = CRCFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); + crcFile = CrcFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); } catch ( IOException e ) { // ... and keep it in ram if it fails - crcFile = new CRCFile( crcSums ); + crcFile = new CrcFile( crcSums ); } image.setCrcFile( crcFile ); } @@ -129,7 +129,7 @@ public class ImageProcessor if ( DbImage.exists( imageData.uuid ) ) { throw new ImageDataException( ImageDataError.INVALID_DATA, "UUID already existing." ); } - if ( !CRCFile.sumsAreValid( crcSums ) ) + if ( !CrcFile.sumsAreValid( crcSums ) ) throw new UploadException( UploadError.INVALID_CRC, "CRC sums were invalid." ); filepath = Globals.getImageDir() + "/" + uuid + ".vmdk"; // TODO: needs to be saved in another way... (Because of the versions.) token = RandomString.generate( 100, false ); @@ -139,13 +139,13 @@ public class ImageProcessor uploadingImages.put( uuid, image ); } - CRCFile crcFile; + CrcFile crcFile; try { // try to write crc file ... - crcFile = CRCFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); //TODO: same here ^ + crcFile = CrcFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); //TODO: same here ^ } catch ( IOException e ) { // ... and keep it in ram if it fails - crcFile = new CRCFile( crcSums ); + crcFile = new CrcFile( crcSums ); } image.setCrcFile( crcFile ); @@ -185,7 +185,7 @@ public class ImageProcessor // 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; + String filepath = DbImage.getImageByUuid( uuid ).imagePath; ConnectionHandler.addConnection( token, filepath, Connection.DOWNLOADING ); client.addDownload( uuid, requestedBlocks, token ); @@ -196,7 +196,7 @@ public class ImageProcessor // insert new client and start listener synchronized ( downloadingClients ) { String token = RandomString.generate( 100, false ); - String filepath = DbImage.getImageByUUID( uuid ).imagePath; + String filepath = DbImage.getImageByUuid( uuid ).imagePath; DownloadingClient client = new DownloadingClient(); client.addDownload( uuid, requestedBlocks, token ); @@ -308,7 +308,7 @@ public class ImageProcessor for ( DbImage image : list ) { UploadingImage infos = new UploadingImage( image.token, image.blockStatus, image.timestamp.getTime(), image.uuid, image.imagePath ); ConnectionHandler.addConnection( image.token, image.imagePath, Connection.UPLOADING ).image = infos; - CRCFile crcFile = new CRCFile( Globals.getImageDir() + "/" + image.uuid + ".crc" ); // TODO: has to be adjusted with the corresponding value above + CrcFile crcFile = new CrcFile( Globals.getImageDir() + "/" + image.uuid + ".crc" ); // TODO: has to be adjusted with the corresponding value above try { if ( !crcFile.isValid() ) { continue; diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java index f67da43..b8a045e 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java @@ -5,7 +5,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.openslx.imagemaster.Globals; -import org.openslx.imagemaster.crcchecker.CRCFile; +import org.openslx.imagemaster.crcchecker.CrcFile; import org.openslx.imagemaster.crcchecker.ImageFile; import org.openslx.imagemaster.db.DbImage; @@ -35,7 +35,7 @@ public class UploadingImage private String uuid; private String filename; private ImageFile imageFile = null; - private CRCFile crcFile = null; + private CrcFile crcFile = null; protected UploadingImage(String token, int[] initialBlockStatus, long timestamp, String uuid, String filename) { @@ -158,7 +158,7 @@ public class UploadingImage protected DbImage getDbImage() { if ( dbImage == null ) { - dbImage = DbImage.getImageByUUID( this.uuid ); + dbImage = DbImage.getImageByUuid( this.uuid ); } return this.dbImage; } @@ -171,12 +171,12 @@ public class UploadingImage return imageFile; } - protected CRCFile getCrcFile() + protected CrcFile getCrcFile() { return crcFile; } - protected void setCrcFile( CRCFile crcFile ) + protected void setCrcFile( CrcFile crcFile ) { this.crcFile = crcFile; } |