diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 8678e4d1..d8fbcb95 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -166,6 +166,8 @@ public class Core { final SigningPrivateKey spk + private final List modules = new ArrayList<>() + public Core(MuWireSettings props, File home, String myVersion) { this.home = home this.version = myVersion @@ -499,9 +501,25 @@ public class Core { register(UIMessageDeleteEvent.class, messenger) register(UIMessageReadEvent.class, messenger) } + + File modulesProps = new File(home, "mwmodules.list") + if (modulesProps.exists()) { + log.info("loading modules") + modulesProps.eachLine { + Class moduleClass = Class.forName(it) + MWModule module = moduleClass.newInstance() + modules.add(module) + } + } } public void startServices() { + + modules.each { + log.info("initializing module ${it.getName()}") + it.init(this) + } + i2pSession.connect() hasherService.start() trustService.start() @@ -516,6 +534,11 @@ public class Core { feedManager.start() feedClient.start() trackerResponder.start() + + modules.each { + log.info("starting module ${it.getName()}") + it.start() + } } public void shutdown() { @@ -523,6 +546,12 @@ public class Core { log.info("already shutting down") return } + + modules.each { + log.info("shutting down module ${it.getName()}") + it.stop() + } + log.info("saving settings") saveMuSettings() log.info("shutting down host cache") diff --git a/core/src/main/groovy/com/muwire/core/MWModule.groovy b/core/src/main/groovy/com/muwire/core/MWModule.groovy new file mode 100644 index 00000000..2a53696e --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/MWModule.groovy @@ -0,0 +1,9 @@ +package com.muwire.core + +interface MWModule { + public String getName() + public void init(Core core) + public void start() + public void stop() +} + diff --git a/mwmodules/build.gradle b/mwmodules/build.gradle new file mode 100644 index 00000000..e20891d1 --- /dev/null +++ b/mwmodules/build.gradle @@ -0,0 +1,3 @@ +dependencies { + compile project(":core") +} diff --git a/mwmodules/src/main/groovy/QueryLogger.groovy b/mwmodules/src/main/groovy/QueryLogger.groovy new file mode 100644 index 00000000..c3fd0476 --- /dev/null +++ b/mwmodules/src/main/groovy/QueryLogger.groovy @@ -0,0 +1,32 @@ +import com.muwire.core.Core +import com.muwire.core.MWModule +import com.muwire.core.search.SearchEvent + +class QueryLogger implements MWModule { + private final File dump = new File("searches.csv") + + void onSearchEvent(SearchEvent e) { + dump.withWriterAppend("UTF-8", {writer -> + String coalesced = String.join(" ", e.searchTerms) + writer.append(String.format("%d,%s,%s\n", e.getTimestamp(), coalesced, e.persona.getHumanReadableName())) + }) + } + + @Override + String getName() { + "QueryLogger" + } + + @Override + void init(Core core) { + core.getEventBus().register(SearchEvent.class, this) + } + + @Override + void start() { + } + + @Override + void stop() { + } +} diff --git a/settings.gradle b/settings.gradle index 4ca40dca..4986601a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ include 'pinger' include 'host-cache' include 'update-server' include 'core' +include 'mwmodules' include 'gui' include 'cli' include 'cli-lanterna'