@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;
}
/**
+ * 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
/* 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()) {
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;
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()));
/* 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()));
}