Use command-line parameters to define directory for states and chains.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Jan 2013 06:16:18 +0000 (07:16 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Jan 2013 06:16:18 +0000 (07:16 +0100)
pom.xml
src/main/java/net/pterodactylus/reactor/engine/Engine.java
src/main/java/net/pterodactylus/reactor/engine/Starter.java

diff --git a/pom.xml b/pom.xml
index 0aa98ee..0130d8b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <artifactId>jackson-databind</artifactId>
                        <version>2.1.2</version>
                </dependency>
+               <dependency>
+                       <groupId>com.lexicalscope.jewelcli</groupId>
+                       <artifactId>jewelcli</artifactId>
+                       <version>0.8.3</version>
+               </dependency>
        </dependencies>
 </project>
index f14d3d7..6f4376b 100644 (file)
@@ -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<String, Reaction> reactions = new HashMap<String, Reaction>();
 
+       /**
+        * Creates a new engine.
+        *
+        * @param stateManager
+        *            The state manager
+        */
+       public Engine(StateManager stateManager) {
+               this.stateManager = stateManager;
+       }
+
        //
        // ACCESSORS
        //
index c3dfa40..0a0941e 100644 (file)
 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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       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();
+
        }
 
 }