From a41f3ea11b088b0ebc17dcc8150f556b78aa7dd8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 9 Jan 2013 07:16:18 +0100 Subject: [PATCH] Use command-line parameters to define directory for states and chains. --- pom.xml | 5 +++ .../net/pterodactylus/reactor/engine/Engine.java | 12 +++++- .../net/pterodactylus/reactor/engine/Starter.java | 45 ++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 0aa98ee..0130d8b 100644 --- a/pom.xml +++ b/pom.xml @@ -73,5 +73,10 @@ jackson-databind 2.1.2 + + com.lexicalscope.jewelcli + jewelcli + 0.8.3 + diff --git a/src/main/java/net/pterodactylus/reactor/engine/Engine.java b/src/main/java/net/pterodactylus/reactor/engine/Engine.java index f14d3d7..6f4376b 100644 --- a/src/main/java/net/pterodactylus/reactor/engine/Engine.java +++ b/src/main/java/net/pterodactylus/reactor/engine/Engine.java @@ -47,12 +47,22 @@ public class Engine extends AbstractExecutionThreadService { private static final Logger logger = Logger.getLogger(Engine.class); /** The state manager. */ - private final StateManager stateManager = new StateManager("states"); + private final StateManager stateManager; /** All defined reactions. */ /* synchronize on itself. */ private final Map reactions = new HashMap(); + /** + * Creates a new engine. + * + * @param stateManager + * The state manager + */ + public Engine(StateManager stateManager) { + this.stateManager = stateManager; + } + // // ACCESSORS // diff --git a/src/main/java/net/pterodactylus/reactor/engine/Starter.java b/src/main/java/net/pterodactylus/reactor/engine/Starter.java index c3dfa40..0a0941e 100644 --- a/src/main/java/net/pterodactylus/reactor/engine/Starter.java +++ b/src/main/java/net/pterodactylus/reactor/engine/Starter.java @@ -18,6 +18,10 @@ package net.pterodactylus.reactor.engine; import net.pterodactylus.reactor.loader.ChainWatcher; +import net.pterodactylus.reactor.states.StateManager; + +import com.lexicalscope.jewel.cli.CliFactory; +import com.lexicalscope.jewel.cli.Option; /** * Reactor main starter class. @@ -34,13 +38,46 @@ public class Starter { */ public static void main(String... arguments) { - /* start the engine. */ - Engine engine = new Engine(); - engine.start(); + /* parse command line. */ + Parameters parameters = CliFactory.parseArguments(Parameters.class, arguments); + + /* create the state manager. */ + StateManager stateManager = new StateManager(parameters.getStateDirectory()); + + /* create the engine. */ + Engine engine = new Engine(stateManager); /* start a watcher. */ - ChainWatcher chainWatcher = new ChainWatcher(engine, "/home/bombe/Documents/Workspace/Reactor/src/main/resources/chains/"); + ChainWatcher chainWatcher = new ChainWatcher(engine, parameters.getChainDirectory()); chainWatcher.start(); + + /* start the engine. */ + engine.start(); + } + + /** + * Definition of the command-line parameters. + * + * @author David ‘Bombe’ Roden + */ + private static interface Parameters { + + /** + * Returns the directory to watch for chains. + * + * @return The chain directory + */ + @Option(defaultValue = "chains", shortName = "c", description = "The directory to watch for chains") + String getChainDirectory(); + + /** + * Returns the directory to store states in. + * + * @return The states directory + */ + @Option(defaultValue = "states", shortName = "s", description = "The directory to store states in") + String getStateDirectory(); + } } -- 2.7.4