From 1fb66d5eb584966802911657ec88f17bca196699 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 11 Jan 2013 07:21:47 +0100 Subject: [PATCH] Parse and load watchers from configuration. --- .../net/pterodactylus/rhynodge/loader/Chain.java | 13 +++++++++++ .../rhynodge/loader/ChainWatcher.java | 26 +++++++++++++--------- .../rhynodge/loader/ReactionLoader.java | 13 ++++++++--- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/loader/Chain.java b/src/main/java/net/pterodactylus/rhynodge/loader/Chain.java index 8fc6c35..2587d09 100644 --- a/src/main/java/net/pterodactylus/rhynodge/loader/Chain.java +++ b/src/main/java/net/pterodactylus/rhynodge/loader/Chain.java @@ -184,6 +184,10 @@ public class Chain { @JsonProperty private Part trigger; + /** A combination of query, filters, and a trigger. */ + @JsonProperty + private Part watcher; + /** The action of the chain. */ @JsonProperty private Part action; @@ -238,6 +242,15 @@ public class Chain { } /** + * Returns an optional watcher. + * + * @return The watcher of this chain + */ + public Part watcher() { + return watcher; + } + + /** * Returns the action of this chain. * * @return The action of this chain diff --git a/src/main/java/net/pterodactylus/rhynodge/loader/ChainWatcher.java b/src/main/java/net/pterodactylus/rhynodge/loader/ChainWatcher.java index 52b3fa4..71320ff 100644 --- a/src/main/java/net/pterodactylus/rhynodge/loader/ChainWatcher.java +++ b/src/main/java/net/pterodactylus/rhynodge/loader/ChainWatcher.java @@ -125,19 +125,23 @@ public class ChainWatcher extends AbstractExecutionThreadService { /* dump chain */ logger.debug(String.format(" Enabled: %s", chain.enabled())); - logger.debug(String.format(" Query: %s", chain.query().name())); - for (Parameter parameter : chain.query().parameters()) { - logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value())); - } - for (Part filter : chain.filters()) { - logger.debug(String.format(" Filter: %s", filter.name())); - for (Parameter parameter : filter.parameters()) { + if (chain.watcher() != null) { + logger.debug(String.format("Reaction: %s", chain.watcher().name())); + } else { + logger.debug(String.format(" Query: %s", chain.query().name())); + for (Parameter parameter : chain.query().parameters()) { + logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value())); + } + for (Part filter : chain.filters()) { + logger.debug(String.format(" Filter: %s", filter.name())); + for (Parameter parameter : filter.parameters()) { + logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value())); + } + } + logger.debug(String.format(" Trigger: %s", chain.trigger().name())); + for (Parameter parameter : chain.trigger().parameters()) { logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value())); } - } - logger.debug(String.format(" Trigger: %s", chain.trigger().name())); - for (Parameter parameter : chain.trigger().parameters()) { - logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value())); } logger.debug(String.format(" Action: %s", chain.action().name())); for (Parameter parameter : chain.action().parameters()) { diff --git a/src/main/java/net/pterodactylus/rhynodge/loader/ReactionLoader.java b/src/main/java/net/pterodactylus/rhynodge/loader/ReactionLoader.java index 2cf1d21..100e42f 100644 --- a/src/main/java/net/pterodactylus/rhynodge/loader/ReactionLoader.java +++ b/src/main/java/net/pterodactylus/rhynodge/loader/ReactionLoader.java @@ -28,6 +28,7 @@ import net.pterodactylus.rhynodge.Filter; import net.pterodactylus.rhynodge.Query; import net.pterodactylus.rhynodge.Reaction; import net.pterodactylus.rhynodge.Trigger; +import net.pterodactylus.rhynodge.Watcher; import net.pterodactylus.rhynodge.loader.Chain.Parameter; import net.pterodactylus.rhynodge.loader.Chain.Part; @@ -55,6 +56,15 @@ public class ReactionLoader { throw new IllegalArgumentException("Chain is not enabled."); } + /* create action. */ + Action action = createObject(chain.action().name(), "net.pterodactylus.rhynodge.actions", extractParameters(chain.action().parameters())); + + /* do we have a reaction defined? */ + if (chain.watcher() != null) { + Watcher watcher = createObject(chain.watcher().name(), "net.pterodactylus.rhynodge.watchers", extractParameters(chain.watcher().parameters())); + return new Reaction(chain.name(), watcher.query(), watcher.filters(), watcher.trigger(), action); + } + /* create query. */ Query query = createObject(chain.query().name(), "net.pterodactylus.rhynodge.queries", extractParameters(chain.query().parameters())); @@ -67,9 +77,6 @@ public class ReactionLoader { /* create trigger. */ Trigger trigger = createObject(chain.trigger().name(), "net.pterodactylus.rhynodge.triggers", extractParameters(chain.trigger().parameters())); - /* create action. */ - Action action = createObject(chain.action().name(), "net.pterodactylus.rhynodge.actions", extractParameters(chain.action().parameters())); - return new Reaction(chain.name(), query, filters, trigger, action).setUpdateInterval(TimeUnit.SECONDS.toMillis(chain.updateInterval())); } -- 2.7.4