compile group: "com.fasterxml.jackson.core", name: "jackson-core", version: "2.1.2"
compile group: "com.fasterxml.jackson.core", name: "jackson-annotations", version: "2.1.2"
compile group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.1.2"
+ compile group: "com.google.inject", name: "guice", version: "4.0"
testCompile group: "junit", name: "junit", version:"4.12"
testCompile group: "org.hamcrest", name: "hamcrest-library", version:"1.3"
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import net.pterodactylus.rhynodge.Reaction;
import net.pterodactylus.rhynodge.actions.EmailAction;
import net.pterodactylus.rhynodge.states.StateManager;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
+@Singleton
public class Engine {
private final StateManager stateManager;
private final Map<String, Future<?>> scheduledFutures = new ConcurrentHashMap<>();
private final EmailAction errorEmailAction;
+ @Inject
public Engine(StateManager stateManager, EmailAction errorEmailAction) {
this.stateManager = stateManager;
this.errorEmailAction = errorEmailAction;
import net.pterodactylus.rhynodge.actions.EmailAction;
import net.pterodactylus.rhynodge.loader.ChainWatcher;
import net.pterodactylus.rhynodge.states.StateManager;
+import net.pterodactylus.rhynodge.states.StateManager.Directory;
import net.pterodactylus.util.envopt.Parser;
/**
Options options = Parser.fromSystemEnvironment().parseEnvironment(Options::new);
/* create the state manager. */
- StateManager stateManager = new StateManager(options.stateDirectory);
+ StateManager stateManager = new StateManager(Directory.of(options.stateDirectory));
/* create the engine. */
Engine engine = new Engine(stateManager, createErrorEmailAction(options.smtpHostname, options.errorEmailSender, options.errorEmailRecipient));
import java.io.IOException;
import java.util.Optional;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import net.pterodactylus.rhynodge.State;
import org.apache.log4j.Logger;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
+@Singleton
public class StateManager {
/** The logger. */
* @param directory
* The directory to store states in
*/
- public StateManager(String directory) {
- this.directory = directory;
+ @Inject
+ public StateManager(Directory directory) {
+ this.directory = directory.getDirectory();
}
//
return empty();
}
+ public static class Directory {
+
+ private final String directory;
+
+ private Directory(String directory) {
+ this.directory = directory;
+ }
+
+ public String getDirectory() {
+ return directory;
+ }
+
+ public static Directory of(String directory) {
+ return new Directory(directory);
+ }
+
+ }
+
}
import java.util.Optional;
import net.pterodactylus.rhynodge.State;
+import net.pterodactylus.rhynodge.states.StateManager.Directory;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.io.Files;
public StateManagerTest() throws IOException {
tempFolder.create();
statePath = tempFolder.newFolder();
- stateManager = new StateManager(statePath.getPath());
+ stateManager = new StateManager(Directory.of(statePath.getPath()));
}
@Test