From e61263a558437dddbe01e35a69e310cc3967eb3d Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Mon, 25 Aug 2014 16:43:53 +0200 Subject: changed static to nonstatic un db class --- .../org/openslx/satellitedaemon/db/DbImage.java | 8 +- .../filetransfer/FileUploadWorker.java | 93 +++++++++++----------- 2 files changed, 52 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java index 77709e7..10438f8 100644 --- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java +++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java @@ -62,14 +62,14 @@ public class DbImage " WHERE image_syncMode = 'to_be_decentralized'" ); } - public static void updateStatus( String uuid, Status status ) + public void updateStatus( Status status ) { - MySQL.update( "UPDATE m_VLData_imageInfo SET image_syncMode=? WHERE GUID_imageID=?", status.toString(), uuid ); + MySQL.update( "UPDATE m_VLData_imageInfo SET image_syncMode=? WHERE GUID_imageID=?", status.toString(), this.guid); } - public static void updateFilesize( String uuid, long filesize ) + public void updateFilesize( long filesize ) { - MySQL.update( "UPDATE m_VLData_imageInfo SET image_filesize=? WHERE GUID_imageID=?", filesize, uuid ); + MySQL.update( "UPDATE m_VLData_imageInfo SET image_filesize=? WHERE GUID_imageID=?", filesize, this.guid ); } } diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java index e19c222..829a903 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java @@ -3,6 +3,7 @@ package org.openslx.satellitedaemon.filetransfer; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.UUID; import org.apache.log4j.Logger; import org.openslx.filetransfer.Uploader; @@ -11,82 +12,84 @@ import org.openslx.imagemaster.thrift.iface.UploadInfos; import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; -public class FileUploadWorker implements Runnable { - private static Logger log = Logger.getLogger(FileUploadWorker.class); +public class FileUploadWorker implements Runnable +{ + private static Logger log = Logger.getLogger( FileUploadWorker.class ); @Override - public void run() { - while (true) { + public void run() + { + while ( true ) { // This List contains all Images in the Database that should be // uploaded. List imageList = DbImage.getAllMarkedForUpload(); - log.info("imageList Contains " + imageList.size() + " items."); + log.info( "imageList Contains " + imageList.size() + " items." ); // Upload one Image after the other. - for (DbImage image : imageList) { + for ( DbImage image : imageList ) { // TODO: still some fields for ImageData, which i can't fill // with info from DbImage. - ImageData imDat = new ImageData(image.guid, image.rid, - image.name, System.currentTimeMillis(), - System.currentTimeMillis(), image.creator, "anyThing", // TODO: fields in databases need to fit somehow... - true, false, "best", "theVeryBest", image.fileSize); + // ImageData imDat = new ImageData(image.guid, image.rid, + // image.name, System.currentTimeMillis(), + // System.currentTimeMillis(), image.creator, "anyThing", // TODO: fields in databases need to fit somehow... + // true, false, "best", "theVeryBest", image.fileSize); - // ImageData imDat = new ImageData( - // UUID.randomUUID().toString(), image.rid, - // image.name, System.currentTimeMillis(), - // System.currentTimeMillis(), image.creator, "anyThing", - // true, false, "best", "theVeryBest", image.fileSize ); + ImageData imDat = new ImageData( + UUID.randomUUID().toString(), image.rid, + image.name, System.currentTimeMillis(), + System.currentTimeMillis(), image.creator, "anyThing", + true, false, "best", "theVeryBest", image.fileSize ); // uploadInfo and ThriftAuthentication - String crcPath = image.path.concat(".crc"); - UploadInfos upInfos = ThriftConnection.getUploadInfos(imDat, - crcPath); - if (upInfos == null) { - log.error("The UploadInfos returned by ThriftConnection Class are null"); + String crcPath = image.path.concat( ".crc" ); + UploadInfos upInfos = ThriftConnection.getUploadInfos( imDat, + crcPath ); + if ( upInfos == null ) { + log.error( "The UploadInfos returned by ThriftConnection Class are null" ); continue; } - log.info("Got upInfos. Trying to create Uploader with token: " - + upInfos.token); + log.info( "Got upInfos. Trying to create Uploader with token: " + + upInfos.token ); // creating the uploader with the "context"-item. Uploader u; try { - u = new Uploader(Globals.getMasterserverHost(), - upInfos.port, Globals.getMasterServerSslContext()); - } catch (IOException e) { - log.warn("Could not connect for uploading an image: " - + e.toString()); + u = new Uploader( Globals.getMasterserverHost(), + upInfos.port, Globals.getMasterServerSslContext() ); + } catch ( IOException e ) { + log.warn( "Could not connect for uploading an image: " + + e.toString() ); continue; } - u.sendToken(upInfos.token); + u.sendToken( upInfos.token ); - log.info("upInfos.getMissingBlocks().size() = " - + upInfos.getMissingBlocks().size()); - long fileSize = new File(image.path).length(); + log.info( "upInfos.getMissingBlocks().size() = " + + upInfos.getMissingBlocks().size() ); + long fileSize = new File( image.path ).length(); // continue sending Blocks until getMissingBlocks is empty. - while (!upInfos.getMissingBlocks().isEmpty()) { + while ( !upInfos.getMissingBlocks().isEmpty() ) { List blocks = upInfos.getMissingBlocks(); - log.info("Anzahl angeforderter Blöcke : " + blocks.size()); - log.info(blocks); - for (int i = 0; i < blocks.size(); i++) { - int startOffset = blocks.get(i) * Globals.BLOCKSIZE; // TODO: - // long + log.info( "Anzahl angeforderter Blöcke : " + blocks.size() ); + log.info( blocks ); + for ( int i = 0; i < blocks.size(); i++ ) { + int startOffset = blocks.get( i ) * Globals.BLOCKSIZE; // TODO: + // long int endOffset = startOffset + Globals.BLOCKSIZE; - if (endOffset > fileSize) - endOffset = (int) fileSize; // TODO: Long - u.prepareSendRange(startOffset, endOffset); - u.sendFile(image.path); - log.info("Block number " + blocks.get(i) + " uploaded."); + if ( endOffset > fileSize ) + endOffset = (int)fileSize; // TODO: Long + u.prepareSendRange( startOffset, endOffset ); + u.sendFile( image.path ); + log.info( "Block number " + blocks.get( i ) + " uploaded." ); } - upInfos = ThriftConnection.getUploadInfos(imDat); + upInfos = ThriftConnection.getUploadInfos( imDat ); } u.close(); } try { - Thread.sleep(1 * 60 * 1000); + Thread.sleep( 1 * 60 * 1000 ); // Thread.sleep( 1000 ); - } catch (InterruptedException e) { + } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); return; } -- cgit v1.2.3-55-g7522