mirror of https://github.com/zlatinb/muwire
retry failed downloads
parent
b308ac2f37
commit
7f46347c0f
|
@ -16,15 +16,23 @@ class DownloadsModel {
|
||||||
private final List<Downloader> downloaders = new ArrayList<>()
|
private final List<Downloader> downloaders = new ArrayList<>()
|
||||||
private final TableModel model = new TableModel("Name", "Status", "Progress", "Speed", "ETA")
|
private final TableModel model = new TableModel("Name", "Status", "Progress", "Speed", "ETA")
|
||||||
|
|
||||||
|
|
||||||
|
private long lastRetryTime
|
||||||
|
|
||||||
DownloadsModel(TextGUIThread guiThread, Core core) {
|
DownloadsModel(TextGUIThread guiThread, Core core) {
|
||||||
this.guiThread = guiThread
|
this.guiThread = guiThread
|
||||||
this.core = core
|
this.core = core
|
||||||
|
|
||||||
core.eventBus.register(DownloadStartedEvent.class, this)
|
core.eventBus.register(DownloadStartedEvent.class, this)
|
||||||
Timer timer = new Timer(true)
|
Timer timer = new Timer(true)
|
||||||
Runnable refreshModel = {refreshModel()}
|
Runnable guiRunnable = {
|
||||||
|
refreshModel()
|
||||||
|
resumeDownloads()
|
||||||
|
}
|
||||||
timer.schedule({
|
timer.schedule({
|
||||||
guiThread.invokeLater(refreshModel)
|
if (core.shutdown.get())
|
||||||
|
return
|
||||||
|
guiThread.invokeLater(guiRunnable)
|
||||||
} as TimerTask, 1000,1000)
|
} as TimerTask, 1000,1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,4 +71,20 @@ class DownloadsModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resumeDownloads() {
|
||||||
|
int retryInterval = core.muOptions.downloadRetryInterval
|
||||||
|
if (retryInterval == 0)
|
||||||
|
return
|
||||||
|
retryInterval *= 1000
|
||||||
|
long now = System.currentTimeMillis()
|
||||||
|
if (now - lastRetryTime > retryInterval) {
|
||||||
|
lastRetryTime = now
|
||||||
|
downloaders.each {
|
||||||
|
def state = it.getCurrentState()
|
||||||
|
if (state == Downloader.DownloadState.FAILED || state == Downloader.DownloadState.DOWNLOADING)
|
||||||
|
it.resume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue