import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import net.pterodactylus.reactor.Reaction;
logger.debug(String.format(" Parameter: %s=%s", parameter.name(), parameter.value()));
}
- chains.put(configurationFile.getName(), chain);
+ chains.put(getReactionName(configurationFile.getName()), chain);
}
/* filter enabled chains. */
logger.debug(String.format("Found %d enabled Chain(s).", enabledChains.size()));
/* check for removed chains. */
+ Set<String> chainsToRemove = new HashSet<String>();
for (Entry<String, Chain> loadedChain : loadedChains.entrySet()) {
/* skip chains that still exist. */
logger.info(String.format("Removing Chain: %s", loadedChain.getKey()));
engine.removeReaction(loadedChain.getKey());
- loadedChains.remove(loadedChain.getKey());
+ chainsToRemove.add(loadedChain.getKey());
+ }
+
+ /* remove removed chains from loaded chains. */
+ for (String reactionName : chainsToRemove) {
+ loadedChains.remove(reactionName);
}
/* check for new chains. */
return null;
}
+ /**
+ * Extracts the name of the reaction from the given filename.
+ *
+ * @param filename
+ * The filename to extract the reaction name from
+ * @return The name of the reaction
+ */
+ private static String getReactionName(String filename) {
+ return (filename.lastIndexOf(".") > -1) ? filename.substring(0, filename.lastIndexOf(".")) : filename;
+ }
+
}