summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-21 20:26:09 +0200
committerSimon Rettberg2015-08-21 20:26:09 +0200
commit1f8d2edf172c35b2396e568383d9e461c058a1fa (patch)
tree90662568b358a6c06df5533fbf67a236ed85fda3 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java
parent[client] tried to fix teh broken (diff)
downloadtutor-module-1f8d2edf172c35b2396e568383d9e461c058a1fa.tar.gz
tutor-module-1f8d2edf172c35b2396e568383d9e461c058a1fa.tar.xz
tutor-module-1f8d2edf172c35b2396e568383d9e461c058a1fa.zip
[server] Implement missing lecture thrift calls, clean up transfer handling a bit
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java56
1 files changed, 32 insertions, 24 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java
index 7180fe3d..504317f3 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveDownload.java
@@ -7,43 +7,29 @@ import java.util.concurrent.ThreadPoolExecutor;
import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.util.Constants;
-import org.openslx.bwlp.thrift.iface.TransferState;
import org.openslx.filetransfer.Uploader;
-public class ActiveDownload {
+public class ActiveDownload extends AbstractTransfer {
private static final Logger LOGGER = Logger.getLogger(ActiveDownload.class);
/**
- * How many concurrent connections per upload
+ * How many concurrent connections per download
*/
private static final int MAX_CONNECTIONS = Math.max(Constants.MAX_DOWNLOADS / 4, 1);
/**
- * Self reference for inner classes.
- */
- private final ActiveDownload activeDownload = this;
-
- /**
* This is a download, so we have uploaders
*/
private List<Uploader> uploads = new ArrayList<>();
private final File sourceFile;
- private final long fileSize;
-
- private final String transferId;
-
- /**
- * TransferState of this upload
- */
- private TransferState state = TransferState.IDLE;
+ private boolean isCanceled = false;
public ActiveDownload(String uuid, File file) {
- this.transferId = uuid;
+ super(uuid);
this.sourceFile = file;
- this.fileSize = file.length();
}
/**
@@ -55,6 +41,9 @@ public class ActiveDownload {
* discarded
*/
public synchronized boolean addConnection(final Uploader connection, ThreadPoolExecutor pool) {
+ if (isCanceled)
+ return false;
+ potentialFinishTime.set(0);
synchronized (uploads) {
if (uploads.size() > MAX_CONNECTIONS)
return false;
@@ -64,7 +53,15 @@ public class ActiveDownload {
pool.execute(new Runnable() {
@Override
public void run() {
- connection.upload(sourceFile.getAbsolutePath());
+ potentialFinishTime.set(0);
+ boolean ret = connection.upload(sourceFile.getAbsolutePath());
+ synchronized (uploads) {
+ uploads.remove(connection);
+ }
+ if (ret && uploads.isEmpty()) {
+ potentialFinishTime.set(System.currentTimeMillis());
+ }
+ lastActivityTime.set(System.currentTimeMillis());
}
});
} catch (Exception e) {
@@ -74,13 +71,24 @@ public class ActiveDownload {
return true;
}
- public boolean isComplete() {
- // TODO Auto-generated method stub
- return false;
+ @Override
+ public synchronized void cancel() {
+ isCanceled = true;
+ synchronized (uploads) {
+ for (Uploader u : uploads) {
+ u.cancel();
+ }
+ }
+ }
+
+ @Override
+ public boolean isActive() {
+ return !isCanceled;
}
- public String getId() {
- return transferId;
+ @Override
+ public int getActiveConnectionCount() {
+ return uploads.size();
}
}