emit an event when all files are loaded

This commit is contained in:
Zlatin Balevsky
2019-06-06 09:10:09 +01:00
parent 52f317a5b7
commit 05b9b37488
3 changed files with 22 additions and 1 deletions

View File

@@ -1,7 +1,10 @@
package com.muwire.cli
import java.util.concurrent.CountDownLatch
import com.muwire.core.Core
import com.muwire.core.MuWireSettings
import com.muwire.core.files.AllFilesLoadedEvent
import com.muwire.core.files.FileHashedEvent
import com.muwire.core.files.FileSharedEvent
@@ -31,9 +34,20 @@ class Cli {
println "Failed to initialize core, exiting"
System.exit(1)
}
def latch = new CountDownLatch(1)
def fileLoader = new Object() {
public void onAllFilesLoadedEvent(AllFilesLoadedEvent e) {
latch.countDown()
}
}
core.eventBus.register(AllFilesLoadedEvent.class, fileLoader)
core.startServices()
println "waiting for files to load"
latch.await()
// now we begin
println "MuWire is ready"

View File

@@ -0,0 +1,6 @@
package com.muwire.core.files
import com.muwire.core.Event
class AllFilesLoadedEvent extends Event {
}

View File

@@ -55,6 +55,7 @@ class PersisterService extends Service {
}
}
}
listener.publish(new AllFilesLoadedEvent())
} catch (IllegalArgumentException|NumberFormatException e) {
log.log(Level.WARNING, "couldn't load files",e)
}