- public static void main(String[] args) throws IOException, InterruptedException {
- if (benchmark)
- System.err.println(ManagementFactory.getRuntimeMXBean().getUptime());
- List<String> plainArgs = new ArrayList<>();
- Map<String, List<String>> options = new HashMap<>();
- String currentOption = null;
- for (int i = 0; i < args.length; i++) {
- if (args[i].startsWith("-")) {
- currentOption = args[i];
- if (!options.containsKey(currentOption))
- options.put(currentOption, new ArrayList<>());
- i++;
- options.get(currentOption).add(args[i]);
- } else {
- plainArgs.add(args[i]);
+ public static void main(String[] args) {
+ try {
+ if (benchmark)
+ System.err.println(ManagementFactory.getRuntimeMXBean().getUptime());
+ List<String> plainArgs = new ArrayList<>();
+ Map<String, List<String>> options = new HashMap<>();
+ String currentOption = null;
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-")) {
+ currentOption = args[i];
+ if ("-h".equals(currentOption) || "--help".equals(currentOption)) {
+ printHelp(System.out);
+ return;
+ }
+ if (!options.containsKey(currentOption))
+ options.put(currentOption, new ArrayList<>());
+ i++;
+ options.get(currentOption).add(args[i]);
+ } else {
+ plainArgs.add(args[i]);
+ }
+ }
+
+ List<String> dir = opt(options, "-d", "--sockets-dir");
+ if (dir.size() > 1)
+ throw new IllegalArgumentException("Only one run directory can be specified");
+ Path targetStateDirectory;
+ if (dir.isEmpty())
+ targetStateDirectory = Paths.get(System.getProperty("user.dir"));
+ else {
+ targetStateDirectory = Paths.get(dir.get(0));
+ if (!Files.exists(targetStateDirectory)) {
+ // we assume argument is the application id
+ targetStateDirectory = getRunDir().resolve(dir.get(0));
+ }