Skip to content

Commit

Permalink
Per-instance config args.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Feb 26, 2016
1 parent b7f9215 commit df54a9e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
20 changes: 1 addition & 19 deletions rapidoid-commons/src/main/java/org/rapidoid/config/Conf.java
Expand Up @@ -36,8 +36,6 @@ public class Conf {


private static final Config ROOT = new Config(); private static final Config ROOT = new Config();


private static volatile String[] args;

static { static {
RapidoidInitializer.initialize(); RapidoidInitializer.initialize();
} }
Expand All @@ -51,24 +49,8 @@ public Map<String, Object> parse(byte[] bytes) {
}; };


public static synchronized void args(String... args) { public static synchronized void args(String... args) {
Conf.args = args;
ConfigHelp.processHelp(args); ConfigHelp.processHelp(args);

ROOT.args(args);
if (args != null) {
for (String arg : args) {
String[] parts = arg.split("=", 2);

if (parts.length > 1) {
ROOT.put(parts[0], parts[1]);
} else {
ROOT.put(parts[0], true);
}
}
}
}

public static String[] getArgs() {
return args;
} }


public static void remove(String name) { public static void remove(String name) {
Expand Down
22 changes: 22 additions & 0 deletions rapidoid-commons/src/main/java/org/rapidoid/config/Config.java
Expand Up @@ -35,6 +35,8 @@ public class Config {


private final Map<String, Object> properties; private final Map<String, Object> properties;


private volatile String[] args;

public Config(Map<String, Object> configProperties) { public Config(Map<String, Object> configProperties) {
this.properties = Collections.synchronizedMap(configProperties); this.properties = Collections.synchronizedMap(configProperties);
} }
Expand Down Expand Up @@ -196,4 +198,24 @@ public void putAll(Map<String, ?> entries) {
properties.putAll((Map<String, Object>) entries); properties.putAll((Map<String, Object>) entries);
} }


public void args(String... args) {
this.args = args;

if (args != null) {
for (String arg : args) {
String[] parts = arg.split("=", 2);

if (parts.length > 1) {
put(parts[0], parts[1]);
} else {
put(parts[0], true);
}
}
}
}

public String[] getArgs() {
return args;
}

} }
Expand Up @@ -30,7 +30,7 @@
public class ConfigHelp { public class ConfigHelp {


public static void processHelp(Object[] args) { public static void processHelp(Object[] args) {
if (args.length == 1 && args[0].equals("--help")) { if (args != null && args.length == 1 && args[0].equals("--help")) {
show("Usage:"); show("Usage:");
show(" java -cp <yourapp>.jar com.yourapp.Main [option1 option2 ...]"); show(" java -cp <yourapp>.jar com.yourapp.Main [option1 option2 ...]");


Expand Down

0 comments on commit df54a9e

Please sign in to comment.