Skip to content

Commit

Permalink
change from EmissaryMode to Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdahlke committed Jan 17, 2025
1 parent 6d80005 commit 2614a2e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/main/java/emissary/command/ServerCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -53,7 +53,7 @@ public int getDefaultPort() {
return DEFAULT_PORT;
}

public EmissaryNode.EmissaryMode getMode() {
public EmissaryNode.Mode getMode() {
return mode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import picocli.CommandLine.ITypeConverter;

public class ServerModeConverter implements ITypeConverter<EmissaryNode.EmissaryMode> {
public class ModeConverter implements ITypeConverter<EmissaryNode.Mode> {

@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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/emissary/directory/EmissaryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -76,22 +76,22 @@ 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;

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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/emissary/server/api/PeersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2614a2e

Please sign in to comment.