diff options
author | Simon Rettberg | 2014-07-02 22:12:01 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-07-02 22:12:01 +0200 |
commit | 9e11f75a579ab7aaf9d834a816d546a9128a9898 (patch) | |
tree | 200870f2a1ab06b74ac49af497b24b896e7685b3 /src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java | |
parent | Adappted to the new Filetransfer class. Ready for testing. (diff) | |
download | satellite-daemon-9e11f75a579ab7aaf9d834a816d546a9128a9898.tar.gz satellite-daemon-9e11f75a579ab7aaf9d834a816d546a9128a9898.tar.xz satellite-daemon-9e11f75a579ab7aaf9d834a816d546a9128a9898.zip |
Added TODOs
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java')
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java index 3ee624e..9276ed9 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java @@ -23,6 +23,8 @@ import org.openslx.satellitedaemon.Globals.PropInt; import org.openslx.satellitedaemon.Globals.PropString; import org.openslx.satellitedaemon.db.DbImage; +// TODO: Rename all this FTP* Stuff (also the constants in Globals) now that we're not using ftp anymore + public class FtpUploadWorker implements Runnable { private static Logger log = Logger.getLogger( FtpUploadWorker.class ); @@ -46,6 +48,8 @@ public class FtpUploadWorker implements Runnable try { // All the necessary KeyStore handling for the "context"-item. + // TODO: Don't do this again and again for every image, but once before the loop (or in the constructor) + // Or better yet in a central spot, as the downloadworker needs the context too. Maybe something like Globals.getMasterServerSslContext() keystore = KeyStore.getInstance( "JKS" ); keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ), passphrase ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ); @@ -58,6 +62,7 @@ public class FtpUploadWorker implements Runnable UploadInfos upInfos = ThriftConnection.getUploadInfos( imDat ); if ( upInfos == null ) { log.error( "The UploadInfos returned by ThriftConnection Class are null" ); + // FIXME: And then..? If you just continue, you'll run into a null pointer exception } // creating the uploader with the "context"-item. @@ -70,19 +75,28 @@ public class FtpUploadWorker implements Runnable List<Integer> blocks = upInfos.getMissingBlocks(); int start = 0; for ( int i = 0; i < blocks.size() - 1; i++ ) { - if ( blocks.get( i ) != ( blocks.get( i + 1 ) - 1 ) ) { + if ( blocks.get( i ) != ( blocks.get( i + 1 ) - 1 ) ) { // TODO: !? u.sendRange expects byte values, upInfos contains block indexes (16MiB) u.sendRange( start, i ); u.sendFile( image.path ); start = i + 1; } - if ( i == blocks.size() - 2 ) { + if ( i == blocks.size() - 2 ) { // TODO: != u.sendRange( start, blocks.size() - 1 ); u.sendFile( image.path ); } } } + // FIXME: Should be inside loop, otherwise you'll only ever upload the first 20 blocks upInfos = ThriftConnection.getUploadInfos( imDat ); + // TODO: Use more local try/catch-blocks, not a big one around everything, so you know what exactly caused the exception + // and can handle it properly. There are roughly 3 types of error/exception you can encounter: + // 1) Expected exception: Something you expect to go wrong, so you handle it in the catch block and let the code flow continue + // 2) Minor exception: Something went wrong and you can't continue trying to upload that image. Try to clean things up that + // you already did (like opening a file, opening a network connection) and then continue with the next image + // 3) Major messup: Something went wrong that will prevent the whole application from continuing to work. Try to finish or cancel + // any operation going on in your application and then exit (and don't forget to log meaningful information about the error) + // Basically all those empty catch blocks below should be moved up and filled with logic. } catch ( NoSuchAlgorithmException e ) { // TODO Auto-generated catch block e.printStackTrace(); @@ -107,8 +121,8 @@ public class FtpUploadWorker implements Runnable try { Thread.sleep( 5 * 60 * 1000 ); } catch ( InterruptedException e ) { - log.error( "FtpUploadWorker: Sleep interrupted" ); - e.printStackTrace(); + Thread.currentThread().interrupt(); + return; } } |