- 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();
+ }