From 00c12cfd493894218a37c195aaad3caaed0de2af Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 3 Jun 2019 15:02:04 +0100 Subject: [PATCH] hook up download retry logic --- .../muwire/core/download/Downloader.groovy | 1 + .../com/muwire/gui/MainFrameModel.groovy | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy index 809cfb70..1f3278cc 100644 --- a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy +++ b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy @@ -119,6 +119,7 @@ public class Downloader { } public void resume() { + currentState = DownloadState.CONNECTING downloadManager.resume(this) } } diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index de54352b..d961fd0a 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -58,7 +58,9 @@ class MainFrameModel { private final Set 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())