retry failed downloads, every 15 minutes by default

pull/4/head
Zlatin Balevsky 2019-06-02 00:22:33 +01:00
parent f41cc39659
commit d2533cc4d6
2 changed files with 33 additions and 13 deletions

View File

@ -6,6 +6,7 @@ class MuWireSettings {
final boolean isLeaf final boolean isLeaf
boolean allowUntrusted boolean allowUntrusted
int downloadRetryInterval
String nickname String nickname
File downloadLocation File downloadLocation
String sharedFiles String sharedFiles
@ -23,6 +24,7 @@ class MuWireSettings {
downloadLocation = new File((String)props.getProperty("downloadLocation", downloadLocation = new File((String)props.getProperty("downloadLocation",
System.getProperty("user.home"))) System.getProperty("user.home")))
sharedFiles = props.getProperty("sharedFiles") sharedFiles = props.getProperty("sharedFiles")
downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","15"))
} }
void write(OutputStream out) throws IOException { void write(OutputStream out) throws IOException {
@ -32,6 +34,7 @@ class MuWireSettings {
props.setProperty("crawlerResponse", crawlerResponse.toString()) props.setProperty("crawlerResponse", crawlerResponse.toString())
props.setProperty("nickname", nickname) props.setProperty("nickname", nickname)
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath()) props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
props.setProperty("downloadRetryInterval", "15")
if (sharedFiles != null) if (sharedFiles != null)
props.setProperty("sharedFiles", sharedFiles) props.setProperty("sharedFiles", sharedFiles)
props.store(out, "") props.store(out, "")

View File

@ -12,6 +12,7 @@ import com.muwire.core.connection.ConnectionAttemptStatus
import com.muwire.core.connection.ConnectionEvent import com.muwire.core.connection.ConnectionEvent
import com.muwire.core.connection.DisconnectionEvent import com.muwire.core.connection.DisconnectionEvent
import com.muwire.core.download.DownloadStartedEvent import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.download.Downloader
import com.muwire.core.files.FileHashedEvent import com.muwire.core.files.FileHashedEvent
import com.muwire.core.files.FileLoadedEvent import com.muwire.core.files.FileLoadedEvent
import com.muwire.core.files.FileSharedEvent import com.muwire.core.files.FileSharedEvent
@ -56,6 +57,21 @@ class MainFrameModel {
volatile Core core volatile Core core
void mvcGroupInit(Map<String, Object> args) { void mvcGroupInit(Map<String, Object> args) {
Timer timer = new Timer("download-pumper", true)
timer.schedule({
runInsideUIAsync {
if (!mvcGroup.alive)
return
builder.getVariable("uploads-table")?.model.fireTableDataChanged()
def downloadTable = builder.getVariable("downloads-table")
int selectedRow = downloadTable.getSelectedRow()
downloadTable.model.fireTableDataChanged()
downloadTable.selectionModel.setSelectionInterval(selectedRow,selectedRow)
}
}, 1000, 1000)
application.addPropertyChangeListener("core", {e -> application.addPropertyChangeListener("core", {e ->
coreInitialized = (e.getNewValue() != null) coreInitialized = (e.getNewValue() != null)
core = e.getNewValue() core = e.getNewValue()
@ -70,20 +86,21 @@ class MainFrameModel {
core.eventBus.register(UploadFinishedEvent.class, this) core.eventBus.register(UploadFinishedEvent.class, this)
core.eventBus.register(TrustEvent.class, this) core.eventBus.register(TrustEvent.class, this)
core.eventBus.register(QueryEvent.class, this) core.eventBus.register(QueryEvent.class, this)
})
Timer timer = new Timer("download-pumper", true)
timer.schedule({
runInsideUIAsync {
if (!mvcGroup.alive)
return
builder.getVariable("uploads-table")?.model.fireTableDataChanged()
def downloadTable = builder.getVariable("downloads-table") int retryInterval = application.context.get("muwire-settings").downloadRetryInterval
int selectedRow = downloadTable.getSelectedRow() if (retryInterval > 0) {
downloadTable.model.fireTableDataChanged() retryInterval *= 60000
downloadTable.selectionModel.setSelectionInterval(selectedRow,selectedRow) timer.schedule({
runInsideUIAsync {
downloads.each {
if (it.downloader.currentState == Downloader.DownloadState.FAILED)
it.downloader.resume()
}
}
}, retryInterval, retryInterval)
} }
}, 1000, 1000)
})
} }
void onUIResultEvent(UIResultEvent e) { void onUIResultEvent(UIResultEvent e) {