/**
* Performs the action.
*
- * @param currentState
- * The current state of a system
- * @param previousState
- * The previous state of the system
+ * @param trigger
+ * The object that triggered the action
*/
- void execute(State currentState, State previousState);
+ void execute(Object 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}.
+ *
+ * @return The object that triggered a change
+ */
+ Object trigger();
+
}
* {@inheritDoc}
*/
@Override
- public void execute(State currentState, State previousState) {
- System.out.println(String.format("currentState: %s, previousState: %s", currentState, previousState));
+ public void execute(Object trigger) {
+ System.out.println(String.format("Triggered by %s.", trigger));
}
}
reactionExecution.addState(state);
/* only run trigger if we have collected two states. */
+ Trigger trigger = nextReaction.trigger();
boolean triggerHit = false;
if (reactionExecution.previousState() != null) {
- Trigger trigger = nextReaction.trigger();
logger.debug("Checking Trigger for changes...");
triggerHit = trigger.triggers(reactionExecution.currentState(), reactionExecution.previousState());
}
logger.debug(String.format("Trigger was hit: %s.", triggerHit));
if (triggerHit) {
logger.info("Executing Action...");
- nextReaction.action().execute(reactionExecution.currentState(), reactionExecution.previousState());
+ nextReaction.action().execute(trigger.trigger());
}
+
}
}
return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object trigger() {
+ return true;
+ }
+
}
return ((FileState) previousState).exists() != ((FileState) currentState).exists();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object trigger() {
+ return null;
+ }
+
}
return (currentFileState.exists() != previousFileState.exists()) || (currentFileState.size() != previousFileState.size()) || (currentFileState.modificationTime() != previousFileState.modificationTime());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object trigger() {
+ return null;
+ }
+
}