- public void addReaction(Reaction reaction) {
- reactions.add(reaction);
- reactionExecutions.put(reaction, new ReactionExecution());
+ public void addReaction(String name, Reaction reaction) {
+ synchronized (reactions) {
+ if (reactions.containsKey(name)) {
+ throw new IllegalStateException(String.format("Engine already contains a Reaction named “%s!”", name));
+ }
+ reactions.put(name, reaction);
+ reactionExecutions.put(reaction, new ReactionExecution());
+ reactions.notifyAll();
+ }
+ }
+
+ /**
+ * Removes the reaction with the given name.
+ *
+ * @param name
+ * The name of the reaction to remove
+ */
+ public void removeReaction(String name) {
+ synchronized (reactions) {
+ if (!reactions.containsKey(name)) {
+ return;
+ }
+ Reaction reaction = reactions.remove(name);
+ reactionExecutions.remove(reaction);
+ reactions.notifyAll();
+ }