diff --git a/src/main/java/emissary/command/ServerCommand.java b/src/main/java/emissary/command/ServerCommand.java index 58b92e7b6d..771ae95914 100644 --- a/src/main/java/emissary/command/ServerCommand.java +++ b/src/main/java/emissary/command/ServerCommand.java @@ -1,8 +1,8 @@ package emissary.command; import emissary.client.EmissaryResponse; +import emissary.command.converter.ModeConverter; import emissary.command.converter.ProjectBaseConverter; -import emissary.command.converter.ServerModeConverter; import emissary.directory.EmissaryNode; import emissary.server.EmissaryServer; import emissary.server.api.Pause; @@ -27,9 +27,9 @@ public class ServerCommand extends ServiceCommand { public static final int DEFAULT_PORT = 8001; - @Option(names = {"-m", "--mode"}, description = "mode: standalone or cluster\nDefault: ${DEFAULT-VALUE}", converter = ServerModeConverter.class, + @Option(names = {"-m", "--mode"}, description = "mode: standalone or cluster\nDefault: ${DEFAULT-VALUE}", converter = ModeConverter.class, defaultValue = "standalone") - private EmissaryNode.EmissaryMode mode; + private EmissaryNode.Mode mode; @Option(names = "--staticDir", description = "path to static assets, loaded from classpath otherwise", converter = ProjectBaseConverter.class) private Path staticDir; @@ -53,7 +53,7 @@ public int getDefaultPort() { return DEFAULT_PORT; } - public EmissaryNode.EmissaryMode getMode() { + public EmissaryNode.Mode getMode() { return mode; } diff --git a/src/main/java/emissary/command/converter/ServerModeConverter.java b/src/main/java/emissary/command/converter/ModeConverter.java similarity index 55% rename from src/main/java/emissary/command/converter/ServerModeConverter.java rename to src/main/java/emissary/command/converter/ModeConverter.java index 76245c510f..ed62d1fb72 100644 --- a/src/main/java/emissary/command/converter/ServerModeConverter.java +++ b/src/main/java/emissary/command/converter/ModeConverter.java @@ -4,15 +4,15 @@ import picocli.CommandLine.ITypeConverter; -public class ServerModeConverter implements ITypeConverter { +public class ModeConverter implements ITypeConverter { @Override - public EmissaryNode.EmissaryMode convert(String s) throws Exception { + public EmissaryNode.Mode convert(String s) throws Exception { switch (s.toLowerCase()) { case "cluster": - return EmissaryNode.EmissaryMode.CLUSTER; + return EmissaryNode.Mode.CLUSTER; case "standalone": - return EmissaryNode.EmissaryMode.STANDALONE; + return EmissaryNode.Mode.STANDALONE; default: throw new IllegalArgumentException("Unknown mode: " + s); } diff --git a/src/main/java/emissary/directory/EmissaryNode.java b/src/main/java/emissary/directory/EmissaryNode.java index 51687910d6..ab7b55d53a 100644 --- a/src/main/java/emissary/directory/EmissaryNode.java +++ b/src/main/java/emissary/directory/EmissaryNode.java @@ -64,7 +64,7 @@ public class EmissaryNode { /** Property that determines if server will shut down in the event a place fails to start */ public static final String STRICT_STARTUP_MODE = "strict.mode"; - public enum EmissaryMode { + public enum Mode { STANDALONE, CLUSTER; } @@ -76,7 +76,7 @@ public enum EmissaryMode { // this is the OS for all practical purposes @Nullable protected String nodeType = null; - protected EmissaryMode nodeMode; + protected Mode nodeMode; protected boolean nodeNameIsDefault = false; @Nullable protected String nodeServiceType = null; @@ -84,14 +84,14 @@ public enum EmissaryMode { protected boolean strictStartupMode = false; public EmissaryNode() { - this(EmissaryMode.STANDALONE); + this(Mode.STANDALONE); } /** * Construct the node. The node name and port are from system properties. The node type is based on the os.name in this * implementation */ - public EmissaryNode(EmissaryMode nodeMode) { + public EmissaryNode(Mode nodeMode) { this.nodeMode = nodeMode; this.nodeName = System.getProperty(NODE_NAME_PROPERTY); if (this.nodeName == null) { @@ -112,7 +112,7 @@ public EmissaryNode(EmissaryMode nodeMode) { this.strictStartupMode = Boolean.parseBoolean(System.getProperty(STRICT_STARTUP_MODE, String.valueOf(false))); } - public EmissaryMode getNodeMode() { + public Mode getNodeMode() { return nodeMode; } @@ -176,7 +176,7 @@ public boolean isValidStandalone() { * True if this node appears to be a stand-alone (non P2P) node */ public boolean isStandalone() { - return isValidStandalone() && getNodeMode().equals(EmissaryMode.STANDALONE); + return isValidStandalone() && getNodeMode().equals(Mode.STANDALONE); } public boolean isStrictStartupMode() { diff --git a/src/test/java/emissary/server/api/PeersIT.java b/src/test/java/emissary/server/api/PeersIT.java index 6088ecf663..ffb85791c0 100644 --- a/src/test/java/emissary/server/api/PeersIT.java +++ b/src/test/java/emissary/server/api/PeersIT.java @@ -44,7 +44,7 @@ public void setup() throws Exception { String projectBase = System.getenv(ConfigUtil.PROJECT_BASE_ENV); ServerCommand cmd = ServerCommand.parse(ServerCommand.class, "-b ", projectBase, "-m", "cluster", "-p", "123456"); cmd.setupServer(); - EmissaryServer server = EmissaryServer.init(cmd, new TestEmissaryNode(EmissaryNode.EmissaryMode.CLUSTER)); + EmissaryServer server = EmissaryServer.init(cmd, new TestEmissaryNode(EmissaryNode.Mode.CLUSTER)); Namespace.bind("EmissaryServer", server); DirectoryPlace directoryPlace = new DirectoryPlace(DIRNAME, server.getNode()); @@ -108,7 +108,7 @@ void peersNoDirectoryPlace() throws NamespaceException { static class TestEmissaryNode extends EmissaryNode { - public TestEmissaryNode(EmissaryNode.EmissaryMode mode) { + public TestEmissaryNode(Mode mode) { super(mode); nodeNameIsDefault = true; }