diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 0e930e14..97dbada5 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -1,5 +1,6 @@ package com.muwire.core +import com.muwire.core.files.PersisterDoneEvent import com.muwire.core.files.PersisterFolderService import java.nio.charset.StandardCharsets @@ -262,7 +263,7 @@ public class Core { log.info "initializing folder persistence service" persisterFolderService = new PersisterFolderService(new File(home, "files"), eventBus) - eventBus.register(UILoadedEvent.class, persisterFolderService) + eventBus.register(PersisterDoneEvent.class, persisterFolderService) eventBus.register(UIPersistFilesEvent.class, persisterFolderService) eventBus.register(FileHashedEvent.class, persisterFolderService) eventBus.register(FileUnsharedEvent.class, persisterFolderService) diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterDoneEvent.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterDoneEvent.groovy new file mode 100644 index 00000000..5d12220c --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/files/PersisterDoneEvent.groovy @@ -0,0 +1,12 @@ +package com.muwire.core.files + +import com.muwire.core.Event + +/** + * Should be triggered by the old PersisterService + * once it has finished reading the old file + * + * @see PersisterService + */ +class PersisterDoneEvent extends Event{ +} diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy index a4534f55..642f8166 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy @@ -19,6 +19,8 @@ import java.util.logging.Level * * The absolute path's 32bit hash to the shared file is used * to build the directory and filename. + * + * This persister only starts working once the old persister has finished loading * @see PersisterFolderService#getJsonPath */ @Log @@ -46,8 +48,8 @@ class PersisterFolderService extends BasePersisterService { persisterExecutor.shutdown() } - void onUILoadedEvent(UILoadedEvent e) { - timer.schedule({ load() } as TimerTask, 1) + void onPersisterDoneEvent(PersisterDoneEvent persisterDoneEvent) { + load() } void onUIPersistFilesEvent(UIPersistFilesEvent e) { diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy index 742de69f..31b3b610 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy @@ -60,16 +60,17 @@ class PersisterService extends BasePersisterService { } } } - // TODO: should PersisterFolderService be the one doing this? - listener.publish(new AllFilesLoadedEvent()) + // Backup the old hashes + location.renameTo( + new File(location.absolutePath + ".bak") + ) + listener.publish(new PersisterDoneEvent()) } catch (IllegalArgumentException e) { log.log(Level.WARNING, "couldn't load files",e) } } else { - // TODO: should PersisterFolderService be the one doing this? - listener.publish(new AllFilesLoadedEvent()) + listener.publish(new PersisterDoneEvent()) } - // TODO: Get rid of the files.json loaded = true }