mirror of https://github.com/zlatinb/muwire
Clear up the event path when starting up the old and new persisters
The new persister won't load anything until the old one has finishedpull/37/head
parent
043028c296
commit
598ab90f63
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue