diff --git a/cli/src/main/groovy/com/muwire/cli/Cli.groovy b/cli/src/main/groovy/com/muwire/cli/Cli.groovy index 07a5b865..1af7e570 100644 --- a/cli/src/main/groovy/com/muwire/cli/Cli.groovy +++ b/cli/src/main/groovy/com/muwire/cli/Cli.groovy @@ -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" diff --git a/core/src/main/groovy/com/muwire/core/files/AllFilesLoadedEvent.groovy b/core/src/main/groovy/com/muwire/core/files/AllFilesLoadedEvent.groovy new file mode 100644 index 00000000..df1a140f --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/files/AllFilesLoadedEvent.groovy @@ -0,0 +1,6 @@ +package com.muwire.core.files + +import com.muwire.core.Event + +class AllFilesLoadedEvent extends Event { +} 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 7028d32b..86b01234 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy @@ -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) }