hook up download retry logic

This commit is contained in:
Zlatin Balevsky
2019-06-03 15:02:04 +01:00
parent 1ee389ff91
commit 00c12cfd49
2 changed files with 21 additions and 12 deletions

View File

@@ -119,6 +119,7 @@ public class Downloader {
}
public void resume() {
currentState = DownloadState.CONNECTING
downloadManager.resume(this)
}
}

View File

@@ -58,7 +58,9 @@ class MainFrameModel {
private final Set<InfoHash> infoHashes = new HashSet<>()
volatile Core core
private long lastRetryTime = System.currentTimeMillis()
void updateTablePreservingSelection(String tableName) {
def downloadTable = builder.getVariable(tableName)
int selectedRow = downloadTable.getSelectedRow()
@@ -96,19 +98,25 @@ class MainFrameModel {
core.eventBus.register(TrustEvent.class, this)
core.eventBus.register(QueryEvent.class, this)
int retryInterval = application.context.get("muwire-settings").downloadRetryInterval
if (retryInterval > 0) {
retryInterval *= 60000
timer.schedule({
runInsideUIAsync {
downloads.each {
if (it.downloader.currentState == Downloader.DownloadState.FAILED)
it.downloader.resume()
timer.schedule({
int retryInterval = application.context.get("muwire-settings").downloadRetryInterval
if (retryInterval > 0) {
retryInterval *= 60000
long now = System.currentTimeMillis()
if (now - lastRetryTime > retryInterval) {
lastRetryTime = now
runInsideUIAsync {
downloads.each {
if (it.downloader.currentState == Downloader.DownloadState.FAILED)
it.downloader.resume()
updateTablePreservingSelection("downloads-table")
}
}
}
}, retryInterval, retryInterval)
}
}
}
}, 60000, 60000)
runInsideUIAsync {
trusted.addAll(core.trustService.good.values())
distrusted.addAll(core.trustService.bad.values())