Return an output instead of a trigger object.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 3 Jan 2013 15:38:33 +0000 (16:38 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 3 Jan 2013 15:38:33 +0000 (16:38 +0100)
src/main/java/net/pterodactylus/reactor/Action.java
src/main/java/net/pterodactylus/reactor/Trigger.java
src/main/java/net/pterodactylus/reactor/actions/EmailAction.java
src/main/java/net/pterodactylus/reactor/actions/StandardOutAction.java
src/main/java/net/pterodactylus/reactor/engine/Engine.java
src/main/java/net/pterodactylus/reactor/triggers/AlwaysTrigger.java
src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java
src/main/java/net/pterodactylus/reactor/triggers/FileStateModifiedTrigger.java
src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java

index 05b2c9e..650c3ad 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.reactor;
 
+import net.pterodactylus.reactor.output.Output;
+
 /**
  * An action is performed when a {@link Trigger} determines that two given
  * {@link State}s of a {@link Query} signify a change.
@@ -28,9 +30,9 @@ public interface Action {
        /**
         * Performs the action.
         *
-        * @param trigger
-        *            The object that triggered the action
+        * @param output
+        *            The output for the action
         */
-       void execute(Object trigger);
+       void execute(Output output);
 
 }
index b2eab0d..fbd9d07 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.reactor;
 
+import net.pterodactylus.reactor.output.Output;
 import net.pterodactylus.reactor.states.FileState;
 
 /**
@@ -42,12 +43,11 @@ public interface Trigger {
        boolean triggers(State currentState, State previousState);
 
        /**
-        * Returns the object (or objects) that triggered a change. This method will
-        * only return a meaningful value when {@link #triggers(State, State)}
-        * returns {@code true}.
+        * Returns the output of this trigger. This will only return a meaningful
+        * value if {@link #triggers(State, State)} returns {@code true}.
         *
-        * @return The object that triggered a change
+        * @return The output of this trigger
         */
-       Object trigger();
+       Output output();
 
 }
index 64673e4..ef9d602 100644 (file)
@@ -29,6 +29,7 @@ import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 
 import net.pterodactylus.reactor.Action;
+import net.pterodactylus.reactor.output.Output;
 
 /**
  * {@link Action} implementation that sends an email containing the triggering
@@ -71,7 +72,7 @@ public class EmailAction implements Action {
         * {@inheritDoc}
         */
        @Override
-       public void execute(Object trigger) {
+       public void execute(Output output) {
                Properties properties = System.getProperties();
                properties.put("mail.smtp.host", hostname);
                Session session = Session.getInstance(properties);
index 91fe7da..8cad092 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.reactor.actions;
 
 import net.pterodactylus.reactor.Action;
 import net.pterodactylus.reactor.State;
+import net.pterodactylus.reactor.output.Output;
 
 /**
  * {@link Action} that simply dumps all {@link State}s to standard output.
@@ -31,8 +32,8 @@ public class StandardOutAction implements Action {
         * {@inheritDoc}
         */
        @Override
-       public void execute(Object trigger) {
-               System.out.println(String.format("Triggered by %s.", trigger));
+       public void execute(Output output) {
+               System.out.println(String.format("Triggered by %s.", output.text("text/plain", -1)));
        }
 
 }
index 4ba7887..9edbdb4 100644 (file)
@@ -159,7 +159,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.trigger());
+                               nextReaction.action().execute(trigger.output());
                        }
 
                }
index 0ca7704..928d213 100644 (file)
@@ -19,6 +19,8 @@ package net.pterodactylus.reactor.triggers;
 
 import net.pterodactylus.reactor.State;
 import net.pterodactylus.reactor.Trigger;
+import net.pterodactylus.reactor.output.DefaultOutput;
+import net.pterodactylus.reactor.output.Output;
 
 /**
  * {@link Trigger} implementation that always triggers.
@@ -39,8 +41,8 @@ public class AlwaysTrigger implements Trigger {
         * {@inheritDoc}
         */
        @Override
-       public Object trigger() {
-               return true;
+       public Output output() {
+               return new DefaultOutput("true").addText("text/plain", "true").addText("text/html", "<div>true</div>");
        }
 
 }
index 5864d79..f3464e9 100644 (file)
@@ -19,6 +19,8 @@ package net.pterodactylus.reactor.triggers;
 
 import net.pterodactylus.reactor.State;
 import net.pterodactylus.reactor.Trigger;
+import net.pterodactylus.reactor.output.DefaultOutput;
+import net.pterodactylus.reactor.output.Output;
 import net.pterodactylus.reactor.states.FileState;
 
 import com.google.common.base.Preconditions;
@@ -48,8 +50,8 @@ public class FileExistenceTrigger implements Trigger {
         * {@inheritDoc}
         */
        @Override
-       public Object trigger() {
-               return null;
+       public Output output() {
+               return new DefaultOutput("File appeared/disappeared").addText("text/plain", "File appeared/disappeared").addText("text/html", "<div>File appeared/disappeared</div>");
        }
 
 }
index 0226734..a598a53 100644 (file)
@@ -20,6 +20,8 @@ package net.pterodactylus.reactor.triggers;
 import static com.google.common.base.Preconditions.checkState;
 import net.pterodactylus.reactor.State;
 import net.pterodactylus.reactor.Trigger;
+import net.pterodactylus.reactor.output.DefaultOutput;
+import net.pterodactylus.reactor.output.Output;
 import net.pterodactylus.reactor.states.FileState;
 
 /**
@@ -46,8 +48,8 @@ public class FileStateModifiedTrigger implements Trigger {
         * {@inheritDoc}
         */
        @Override
-       public Object trigger() {
-               return null;
+       public Output output() {
+               return new DefaultOutput("File modified").addText("text/plain", "File modified").addText("text/html", "<div>File modified</div>");
        }
 
 }
index 1eb2247..f655ff0 100644 (file)
@@ -62,8 +62,9 @@ public class NewTorrentTrigger implements Trigger {
         * {@inheritDoc}
         */
        @Override
-       public Object trigger() {
-               return torrentFiles;
+       public Output output() {
+               DefaultOutput output = new DefaultOutput(String.format("Found %d new Torrent(s)!", torrentFiles.size()));
+               return output;
        }
 
 }