summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Schwabe2014-07-07 14:36:22 +0200
committerNils Schwabe2014-07-07 14:36:22 +0200
commitbf8913eb78d7f1a461ade9cc3696e0f9ce253e25 (patch)
tree7e694e7f95a6422138a8904a4c69cfab5597c169
parentBegin to implement crc scheduler... (not working) (diff)
downloadmasterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.tar.gz
masterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.tar.xz
masterserver-bf8913eb78d7f1a461ade9cc3696e0f9ce253e25.zip
Add port to up- and download thingis
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java6
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClientInfos.java14
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java29
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java11
4 files changed, 40 insertions, 20 deletions
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
index 1a2ff0b..1c12e70 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
@@ -95,15 +95,17 @@ public class ConnectionHandler implements IncomingEvent
* @param token The unique token
* @param filepath The file to up- or download
* @param type True if upload or false if download
+ * @return The port that was used for this connection.
*/
- public static void addConnection(String token, String filepath, boolean type)
+ public static int addConnection(String token, String filepath, boolean type)
{
- int port = possiblePorts.remove( 0 );
+ int port = possiblePorts.remove( 0 ); //TODO: handle if no ports are left
Listener listener = new Listener( eventHandler, sslContext, port );
listener.start();
activeListeners.put( token, new ConnectionData(filepath, type, listener) );
+ return port;
}
public static boolean hasConnection( String token )
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClientInfos.java b/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClientInfos.java
index a403c84..4735938 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClientInfos.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClientInfos.java
@@ -16,9 +16,9 @@ public class DownloadingClientInfos
{
}
- public void addDownload( String uuid, List<Integer> list, String token )
+ public void addDownload( String uuid, int port, List<Integer> list, String token )
{
- downloadingImages.put( uuid, new ImageInfos( uuid, list, token ) );
+ downloadingImages.put( uuid, new ImageInfos( uuid, port, list, token ) );
}
public void removeDownload( String uuid )
@@ -57,18 +57,26 @@ public class DownloadingClientInfos
return downloadingImages.get( uuid ).token;
}
+ public int getPort( String uuid )
+ {
+ return downloadingImages.get( uuid ).port;
+ }
+
class ImageInfos
{
public final String uuid;
public final String token;
+ public final int port;
private List<Integer> lastRequestedBlocks;
- ImageInfos(String uuid, List<Integer> list, String token)
+ ImageInfos(String uuid, int port, List<Integer> list, String token)
{
this.uuid = uuid;
this.lastRequestedBlocks = list;
this.token = token;
+ this.port = port;
}
}
+
}
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
index 05c094b..94d55ed 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
@@ -66,10 +66,11 @@ public class ImageProcessor
List<Integer> missing = getMissingBlocks( uuid, AMOUNT );
if ( missing.isEmpty() ) {
uploadDone( uuid );
- return new UploadInfos( null, missing );
+ return new UploadInfos( null, 0, missing );
}
uploadingImages.get( uuid ).addNotCheckedBlocks( missing );
- return new UploadInfos( uploadingImages.get( uuid ).getToken(), missing );
+ UploadingImageInfos image = uploadingImages.get( uuid );
+ return new UploadInfos( image.getToken(), image.getPort(), missing );
}
// insert new image and start listener
@@ -81,11 +82,11 @@ public class ImageProcessor
}
String token = RandomString.generate( 100, false );
String filepath = Globals.getImageDir() + "/" + uuid + ".vmdk";
- ConnectionHandler.addConnection( token, filepath, ConnectionData.UPLOADING );
+ int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.UPLOADING );
// 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() ), uuid, filepath, "CRCFILE" ) );
+ uploadingImages.put( uuid, new UploadingImageInfos( token, port, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid, filepath, "CRCFILE" ) );
DbImage.insert( imageData, System.currentTimeMillis(), token, allBlocks, serverSessionId, filepath );
imagesToCheck.add( uuid );
@@ -95,7 +96,7 @@ public class ImageProcessor
uploadDone( uuid );
}
uploadingImages.get( uuid ).addNotCheckedBlocks( missing );
- return new UploadInfos( token, missing );
+ return new UploadInfos( token, port, missing );
}
}
@@ -117,17 +118,17 @@ public class ImageProcessor
// client was downloading this image
// update the requested blocks
client.requestBlocks( uuid, requestedBlocks );
- return new DownloadInfos( client.getToken( uuid ) );
+ return new DownloadInfos( client.getToken( uuid ), client.getPort( uuid ) );
}
// 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;
- client.addDownload( uuid, requestedBlocks, token );
+ int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING );
+ client.addDownload( uuid, port, requestedBlocks, token );
downloadingClients.put( serverSessionId, client );
- ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING );
- return new DownloadInfos( token );
+ return new DownloadInfos( token, port );
}
// insert new client and start listener
@@ -135,11 +136,11 @@ public class ImageProcessor
DownloadingClientInfos client = new DownloadingClientInfos();
String token = RandomString.generate( 100, false );
String filepath = DbImage.getImageByUUID( uuid ).imagePath;
- client.addDownload( uuid, requestedBlocks, token );
+ int port = ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING );
+ client.addDownload( uuid, port, requestedBlocks, token );
downloadingClients.put( serverSessionId, client );
- ConnectionHandler.addConnection( token, filepath, ConnectionData.DOWNLOADING );
- return new DownloadInfos( token );
+ return new DownloadInfos( token, port );
}
}
@@ -222,8 +223,8 @@ public class ImageProcessor
List<DbImage> list = DbImage.getUploadingImages();
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, image.uuid, image.imagePath, "CRCFILE" );
+ int port = ConnectionHandler.addConnection( token, image.imagePath, ConnectionData.UPLOADING );
+ UploadingImageInfos infos = new UploadingImageInfos( token, port, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid, image.imagePath, "CRCFILE" );
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 210586f..bf851bc 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImageInfos.java
@@ -17,6 +17,10 @@ public class UploadingImageInfos
*/
private String token;
/**
+ * The port where the server is listening.
+ */
+ private int port;
+ /**
* The missing blocks that need to be uploaded by the satellite.
*/
private List<Integer> missingBlocks;
@@ -32,7 +36,7 @@ public class UploadingImageInfos
private String filename;
private String crcFilename;
- protected UploadingImageInfos(String token, List<Integer> missingBlocks, String serverSessionId, Timestamp ts, String uuid, String filename, String crcFilename)
+ protected UploadingImageInfos(String token, int port, List<Integer> missingBlocks, String serverSessionId, Timestamp ts, String uuid, String filename, String crcFilename)
{
this.token = token;
this.missingBlocks = missingBlocks;
@@ -99,4 +103,9 @@ public class UploadingImageInfos
{
return this.crcFilename;
}
+
+ public int getPort()
+ {
+ return this.port;
+ }
}