Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
041cc67
commit 7676385
Showing
8 changed files
with
218 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
rapidoid-config/src/main/java/org/rapidoid/config/ConfigHelp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.rapidoid.config; | ||
|
||
import org.rapidoid.u.U; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-config | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 5.0.2 | ||
*/ | ||
public class ConfigHelp { | ||
|
||
public static void processHelp(Object[] args) { | ||
if (args.length == 1 && args[0].equals("--help")) { | ||
show("Usage:"); | ||
show(" java -cp <yourapp>.jar com.yourapp.Main [option1 option2 ...]"); | ||
|
||
show("\nExample:"); | ||
show(" java -cp <yourapp>.jar com.yourapp.Main port=9090 address=127.0.0.1 cpus=2 workers=4 nodelay"); | ||
|
||
show("\nAvailable options:"); | ||
|
||
for (ConfigOption opt : ConfigOptions.ALL) { | ||
String desc = U.frmt("%s (default: %s)", opt.getDesc(), opt.getDefaultValue()); | ||
opt(opt.getName(), desc); | ||
} | ||
|
||
System.exit(0); | ||
} | ||
} | ||
|
||
private static void opt(String opt, String desc) { | ||
show(" " + opt + U.mul(" ", 21 - opt.length()) + " - " + desc); | ||
} | ||
|
||
private static void show(String msg) { | ||
System.out.println(msg); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
rapidoid-config/src/main/java/org/rapidoid/config/ConfigOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.rapidoid.config; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-config | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 5.0.2 | ||
*/ | ||
public class ConfigOption { | ||
|
||
public final String name; | ||
|
||
public final String desc; | ||
|
||
public final Object defaultValue; | ||
|
||
public ConfigOption(String name, String desc, Object defaultValue) { | ||
this.name = name; | ||
this.desc = desc; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
rapidoid-config/src/main/java/org/rapidoid/config/ConfigOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.rapidoid.config; | ||
|
||
import java.util.List; | ||
|
||
import org.rapidoid.u.U; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-config | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 5.0.2 | ||
*/ | ||
public class ConfigOptions { | ||
|
||
public static final List<ConfigOption> ALL = configOptions(); | ||
|
||
private static List<ConfigOption> configOptions() { | ||
List<ConfigOption> opts = U.list(); | ||
|
||
opts.add(opt("mode=(dev|production)", "configure DEV or PRODUCTION mode", "auto-detected")); | ||
opts.add(opt("secret=<SECRET>", "configure app-specific secret token for encryption", null)); | ||
opts.add(opt("port=<P>", "listen at port P", 8888)); | ||
opts.add(opt("address=<ADDR>", "listen at address ADDR", "0.0.0.0")); | ||
// opts.add(opt("stateless", "Run in stateless mode, session becomes cookiepack", false)); | ||
opts.add(opt("threads=<T>", "start T threads for the job executor service", 100)); | ||
opts.add(opt("cpus=<C>", "optimize for C number of CPUs", "the actual number of the CPUs")); | ||
opts.add(opt("workers=<W>", "start W number of I/O workers", "the configured number of CPUs - cpus options")); | ||
opts.add(opt("nodelay", "set the TCP_NODELAY flag to disable Nagle's algorithm", false)); | ||
opts.add(opt("blockingAccept", "accept connection in BLOCKING mode", false)); | ||
opts.add(opt("bufSizeKB=<SIZE>", "TCP socket buffer size in KB", 16)); | ||
|
||
return opts; | ||
} | ||
|
||
private static ConfigOption opt(String name, String desc, Object def) { | ||
return new ConfigOption(name, desc, def); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
rapidoid-config/src/test/java/org/rapidoid/config/ConfigOptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.rapidoid.config; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-config | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.rapidoid.annotation.Authors; | ||
import org.rapidoid.annotation.Since; | ||
|
||
@Authors("Nikolche Mihajlovski") | ||
@Since("5.0.2") | ||
public class ConfigOptionsTest { | ||
|
||
public static void main(String[] args) { | ||
Conf.args(new String[] { "--help" }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
rapidoid-main/src/main/java/org/rapidoid/main/MainHelp.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters