summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/serverconnection
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/serverconnection')
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java20
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java31
2 files changed, 34 insertions, 17 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
index bf21c71..272b924 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
@@ -79,7 +79,7 @@ public class ImageProcessor
// 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() ) ) );
+ uploadingImages.put( uuid, new UploadingImageInfos( token, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid ) );
DbImage.insert( imageData, System.currentTimeMillis(), token, allBlocks, serverSessionId, filepath );
List<Integer> missing = getMissingBlocks( uuid, AMOUNT );
@@ -167,11 +167,11 @@ public class ImageProcessor
for ( int i = 0; i < amount; i++ ) {
result.add( list.get( i ) );
}
-
- synchronized( image ) {
+
+ synchronized ( image ) {
image.setLastSentBlocks( result );
}
-
+
return result;
}
@@ -183,14 +183,14 @@ public class ImageProcessor
*/
private static void uploadDone( String uuid )
{
- String token;
+ UploadingImageInfos image;
synchronized ( uploadingImages ) {
- token = uploadingImages.remove( uuid ).getToken();
+ image = uploadingImages.remove( uuid );
}
- DbImage.updateMissingBlocks( uuid, null );
+ image.getDbImage().updateMissingBlocks( null );
// file was already downloaded in the right location by the updownloader class.
// remove the connection so that it can be used by a new client
- ConnectionHandler.removeConnection( token );
+ ConnectionHandler.removeConnection( image.getToken() );
}
/**
@@ -202,8 +202,8 @@ public class ImageProcessor
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 );
- uploadingImages.put( image.UUID, infos );
+ UploadingImageInfos infos = new UploadingImageInfos( token, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid );
+ uploadingImages.put( image.uuid, infos );
}
log.info( "Added " + list.size() + " pending upload(s) to process list again." );
}
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java
index 17debbe..547916f 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java
@@ -5,11 +5,14 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import org.openslx.imagemaster.db.DbImage;
+
/**
* Helper class for ImageProcessor to save some infos about the images in the process list.
*/
public class UploadingImageInfos
{
+
/**
* Token for the satellite.
*/
@@ -25,13 +28,16 @@ public class UploadingImageInfos
private List<Integer> lastSentBlocks = new LinkedList<>();
private String serverSessionId;
private Timestamp ts; // when did the server something for the last time
+ private DbImage dbImage = null; // the DB representation of this image
+ private String uuid;
- protected UploadingImageInfos(String token, List<Integer> missingBlocks, String serverSessionId, Timestamp ts)
+ protected UploadingImageInfos(String token, List<Integer> missingBlocks, String serverSessionId, Timestamp ts, String uuid)
{
this.token = token;
this.missingBlocks = missingBlocks;
this.serverSessionId = serverSessionId;
this.ts = ts;
+ this.uuid = uuid;
}
protected void removeBlock( int number )
@@ -43,12 +49,14 @@ public class UploadingImageInfos
{
this.missingBlocks.removeAll( list );
}
-
- protected void setLastSentBlocks(List<Integer> list) {
+
+ protected void setLastSentBlocks( List<Integer> list )
+ {
this.lastSentBlocks = list;
}
-
- protected List<Integer> getLastSentBlocks() {
+
+ protected List<Integer> getLastSentBlocks()
+ {
return this.lastSentBlocks;
}
@@ -66,8 +74,17 @@ public class UploadingImageInfos
{
return this.serverSessionId;
}
-
- protected Timestamp getTimestamp() {
+
+ protected Timestamp getTimestamp()
+ {
return this.ts;
}
+
+ protected DbImage getDbImage()
+ {
+ if ( dbImage == null ) {
+ dbImage = DbImage.getImageByUUID( this.uuid );
+ }
+ return this.dbImage;
+ }
}