public void run() throws IllegalArgumentException, MalformedURLException, RepositoryException {
    final String url = getArgument("url", "http://localhost:8080");
    final String user = getArgument("user", "admin");
    final String password = getArgument("password", "changeit");

    System.err.println("Using RapidAnalytics server at " + url + "...");
    RemoteRepository repository =
        new RemoteRepository(new URL(url), "Temp", user, password.toCharArray(), true);
    RepositoryManager.getInstance(null).addRepository(repository);
    //
    //		GlobalAuthenticator.registerServerAuthenticator(new URLAuthenticator() {
    //			@Override
    //			public String getName() {
    //				return "Dummy command line authenticator";
    //			}
    //
    //			@Override
    //			public PasswordAuthentication getAuthentication(URL url) {
    //				return new PasswordAuthentication(user, password.toCharArray());
    //			}
    //		});

    if (isArgumentSet("check-state")) {
      long startTime;
      try {
        final RepositoryService repoService = repository.getRepositoryService();
        startTime = System.currentTimeMillis();
        repoService.getFolderContents("/");
      } catch (Exception e) {
        System.err.println("Error checking state of RapidAnalytics server at " + url + ": " + e);
        System.exit(1);
        return;
      }
      long responseTime = System.currentTimeMillis() - startTime;
      System.err.println(
          "RapidAnalytics server at " + url + " is up. Response time was " + responseTime + " ms.");
      System.exit(0);
      return;
    }

    if (isArgumentSet("wait-for-start")) {
      int waitForStart = getArgumentInt("wait-for-start", 120);
      long startTime = System.currentTimeMillis();
      long waitUntil = startTime + 1000 * waitForStart;
      Exception lastException;
      do {
        System.err.println("Checking server " + url);
        try {
          getManagementService(url, user, password);

          System.err.println("Server " + url + " is up.");
          System.exit(0);
          return;
        } catch (Exception e) {
          lastException = e;
          System.err.println("Server is not yet up: " + e);
          try {
            Thread.sleep(2000);
          } catch (InterruptedException e1) {
          }
        }
      } while (System.currentTimeMillis() < waitUntil);
      System.err.println("Server at " + url + " did not come up within " + waitForStart + "s.");
      if (lastException != null) {
        System.err.println("Last exception was: " + lastException);
        lastException.printStackTrace();
      }
      System.exit(1);
      return;
    }

    if (isArgumentSet("set-property")) {
      String property = getArgument("set-property", null);
      if (property == null) {
        System.err.println("Argument of --set-property must be of the form KEY=VALUE");
        System.exit(1);
        return;
      }
      String[] split = property.split("=", 2);
      if (split.length != 2) {
        System.err.println("Argument of --set-property must be of the form KEY=VALUE");
        System.exit(1);
        return;
      }
      String key = split[0];
      String value = split[1];
      try {
        ManagementService managementService = getManagementService(url, user, password);
        System.err.println("Setting " + key + " to value '" + value + "'");
        managementService.setGlobalProperty(key, value);
        System.exit(0);
      } catch (Exception e) {
        System.err.println("Failed to set property: " + e);
        e.printStackTrace();
        System.exit(1);
      }
      return;
    }

    if (isArgumentSet("check-setup")) {
      try {
        ManagementService managementService = getManagementService(url, user, password);
        System.err.println("Checking RapidAnalytics setup.");
        if (managementService.checkSetup()) {
          System.err.println("Setup is ok.");
          System.exit(0);
        } else {
          System.err.println("Setup is incomplete.");
          System.exit(1);
        }
      } catch (Exception e) {
        System.err.println("Failed to set property: " + e);
        e.printStackTrace();
        System.exit(1);
      }

      return;
    }

    delay = getArgumentInt("delay", 1000);
    if ("true".equals(getArgument("watch", "false"))) {
      watch = true;
      dumpStatus = true;
    }

    int processId = -1;
    String executeProcess = getArgument("execute-process", null);
    if (executeProcess != null) {
      System.err.println("Scheduling process execution for process " + executeProcess);
      ExecutionResponse result =
          repository.getProcessService().executeProcessSimple(executeProcess, null, null);
      if (result.getStatus() != 0) {
        System.err.println(
            "ERROR. Server responded with code "
                + result.getStatus()
                + ": "
                + result.getErrorMessage());
        System.exit(result.getStatus());
      } else {
        System.out.println("Process scheduled for " + result.getFirstExecution());
        int jobId = result.getJobId();
        if (dumpStatus) {
          processId = getJobId(jobId, repository.getProcessService());
        } else {
          processId = -1;
        }
      }
    } else {
      processId = getArgumentInt("process-id", -1);
      if (processId != -1) {
        dumpStatus = true;
      }
    }

    if (dumpStatus) {
      if (processId == -1) {
        throw new IllegalArgumentException(
            "You must use --process-id or --execute-service if --watch=true.");
      }
      RemoteProcessState state;
      do {
        ProcessResponse pInfo = repository.getProcessService().getRunningProcessesInfo(processId);
        if (pInfo == null) {
          throw new IllegalArgumentException("Process with id " + processId + " does not exist.");
        }
        dump(pInfo, System.out);
        if (watch) {
          try {
            Thread.sleep(delay);
          } catch (InterruptedException e) {
          }
        }
        state = RemoteProcessState.valueOf(pInfo.getState());
      } while (watch && !state.isTerminated());
      if (!state.isSuccessful()) {
        System.exit(1);
      } else {
        System.exit(0);
      }
    }
  }