summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java78
1 files changed, 0 insertions, 78 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 031a807..0000000
--- a/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java
+++ /dev/null
@@ -1,78 +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.Globals;
-import org.openslx.imagemaster.crcchecker.CrcChecker;
-
-/**
- * Class to schedule CRC checks.
- * CRC checks of uploading images are so done parallel to the connection.
- */
-public class CrcScheduler extends TimerTask
-{
-
- private static Logger log = Logger.getLogger( CrcScheduler.class );
-
- @Override
- public void run()
- {
- List<UploadingImage> list = ImageProcessor.getImagesToCheck();
- if ( list == null || list.isEmpty() )
- return;
- log.debug( "Starting checks: " + list );
- Iterator<UploadingImage> iter = list.iterator();
- // iterate over the uploading images that need to be checked
- while ( iter.hasNext() ) {
- UploadingImage image = iter.next();
- log.debug( "Checking blocks of " + image.getUuid() );
- 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, Globals.getCrcSchedulingInterval() * 1000L );
- }
-
-}