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.
/**
* 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);
}
package net.pterodactylus.reactor;
+import net.pterodactylus.reactor.output.Output;
import net.pterodactylus.reactor.states.FileState;
/**
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();
}
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
* {@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);
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.
* {@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)));
}
}
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());
}
}
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.
* {@inheritDoc}
*/
@Override
- public Object trigger() {
- return true;
+ public Output output() {
+ return new DefaultOutput("true").addText("text/plain", "true").addText("text/html", "<div>true</div>");
}
}
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;
* {@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>");
}
}
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;
/**
* {@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>");
}
}
* {@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;
}
}