From 44e9921d5af6f500180238b297d8b6b2bb069205 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 7 Jan 2013 10:25:21 +0100 Subject: [PATCH 1/1] Make reaction available when retrieving output from trigger. --- src/main/java/net/pterodactylus/reactor/Trigger.java | 4 +++- src/main/java/net/pterodactylus/reactor/engine/Engine.java | 2 +- src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java | 3 ++- .../java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java | 3 ++- .../net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java | 3 ++- .../java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/reactor/Trigger.java b/src/main/java/net/pterodactylus/reactor/Trigger.java index fbd9d07..277eeb6 100644 --- a/src/main/java/net/pterodactylus/reactor/Trigger.java +++ b/src/main/java/net/pterodactylus/reactor/Trigger.java @@ -46,8 +46,10 @@ public interface Trigger { * Returns the output of this trigger. This will only return a meaningful * value if {@link #triggers(State, State)} returns {@code true}. * + * @param reaction + * The reaction being triggered * @return The output of this trigger */ - Output output(); + Output output(Reaction reaction); } diff --git a/src/main/java/net/pterodactylus/reactor/engine/Engine.java b/src/main/java/net/pterodactylus/reactor/engine/Engine.java index fe57b33..f14d3d7 100644 --- a/src/main/java/net/pterodactylus/reactor/engine/Engine.java +++ b/src/main/java/net/pterodactylus/reactor/engine/Engine.java @@ -192,7 +192,7 @@ public class Engine extends AbstractExecutionThreadService { logger.debug(String.format("Trigger was hit: %s.", triggerHit)); if (triggerHit) { logger.info("Executing Action..."); - nextReaction.action().execute(trigger.output()); + nextReaction.action().execute(trigger.output(nextReaction)); } } diff --git a/src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java index 928d213..5971553 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java @@ -17,6 +17,7 @@ package net.pterodactylus.reactor.triggers; +import net.pterodactylus.reactor.Reaction; import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.Trigger; import net.pterodactylus.reactor.output.DefaultOutput; @@ -41,7 +42,7 @@ public class AlwaysTrigger implements Trigger { * {@inheritDoc} */ @Override - public Output output() { + public Output output(Reaction reaction) { return new DefaultOutput("true").addText("text/plain", "true").addText("text/html", "
true
"); } diff --git a/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java index f3464e9..a285843 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java @@ -17,6 +17,7 @@ package net.pterodactylus.reactor.triggers; +import net.pterodactylus.reactor.Reaction; import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.Trigger; import net.pterodactylus.reactor.output.DefaultOutput; @@ -50,7 +51,7 @@ public class FileExistenceTrigger implements Trigger { * {@inheritDoc} */ @Override - public Output output() { + public Output output(Reaction reaction) { return new DefaultOutput("File appeared/disappeared").addText("text/plain", "File appeared/disappeared").addText("text/html", "
File appeared/disappeared
"); } diff --git a/src/main/java/net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java index a598a53..39044c3 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java @@ -18,6 +18,7 @@ package net.pterodactylus.reactor.triggers; import static com.google.common.base.Preconditions.checkState; +import net.pterodactylus.reactor.Reaction; import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.Trigger; import net.pterodactylus.reactor.output.DefaultOutput; @@ -48,7 +49,7 @@ public class FileStateModifiedTrigger implements Trigger { * {@inheritDoc} */ @Override - public Output output() { + public Output output(Reaction reaction) { return new DefaultOutput("File modified").addText("text/plain", "File modified").addText("text/html", "
File modified
"); } diff --git a/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java index 19268e9..f97002a 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.List; +import net.pterodactylus.reactor.Reaction; import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.Trigger; import net.pterodactylus.reactor.output.DefaultOutput; @@ -70,7 +71,7 @@ public class NewTorrentTrigger implements Trigger { * {@inheritDoc} */ @Override - public Output output() { + public Output output(Reaction reaction) { DefaultOutput output = new DefaultOutput(String.format("Found %d new Torrent(s)!", torrentFiles.size())); output.addText("text/plain", getPlainTextList(torrentFiles)); output.addText("text/html", getHtmlTextList(torrentFiles)); -- 2.7.4