+ private File stateFile(String reactionName, String suffix) {
+ return new File(directory, reactionName + ((suffix != null) ? "." + suffix : "") + ".json");
+ }
+
+ /**
+ * Load the given state for the reaction with the given name.
+ *
+ * @param reactionName
+ * The name of the reaction
+ * @param successful
+ * {@code true} to load the last successful state, {@code false}
+ * to load the last state
+ * @return The loaded state, or {@code null} if the state could not be
+ * loaded
+ */
+ private State loadLastState(String reactionName, boolean successful) {
+ File stateFile = stateFile(reactionName, successful ? "success" : "last");
+ try {
+ State state = objectMapper.readValue(stateFile, AbstractState.class);
+ return state;
+ } catch (JsonParseException jpe1) {
+ logger.warn(String.format("State for Reaction “%s” could not be parsed.", reactionName), jpe1);
+ } catch (JsonMappingException jme1) {
+ logger.warn(String.format("State for Reaction “%s” could not be parsed.", reactionName), jme1);
+ } catch (IOException ioe1) {
+ logger.info(String.format("State for Reaction “%s” could not be found.", reactionName));
+ }
+ return null;