Example #1
0
  public void run() {
    try {
      while (!stop) {
        if (LogInfo.writeToStdout) readAndProcessCommand();

        // Input commands
        Execution.inputMap.readEasy(Execution.getFile("input.map"));

        boolean killed = Execution.create && new File(Execution.getFile("kill")).exists();
        if (killed) Execution.setExecStatus("killed", true);

        // Output status
        Execution.putOutput("log.note", LogInfo.note);
        Execution.putOutput("exec.memory", SysInfoUtils.getUsedMemoryStr());
        Execution.putOutput(
            "exec.time", new StopWatch(LogInfo.getWatch().getCurrTimeLong()).toString());
        Execution.putOutput("exec.errors", "" + LogInfo.getNumErrors());
        Execution.putOutput("exec.warnings", "" + LogInfo.getNumWarnings());
        Execution.setExecStatus("running", false);
        Execution.printOutputMap(Execution.getFile("output.map"));

        if (killed) throw new RuntimeException("Killed by 'kill' file");

        Utils.sleep(timeInterval);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1); // Die completely
    }
  }
Example #2
0
 void processCommand(String cmd) {
   cmd = cmd.trim();
   if (cmd.equals("")) {
     // Print status
     Execution.getInfo().print(stderr);
     Execution.printOutputMapToStderr();
     StopWatchSet.getStats().print(stderr);
     stderr.println(Execution.getVirtualExecDir());
   } else if (cmd.equals("kill")) {
     stderr.println("MonitorThread: KILLING");
     Execution.setExecStatus("killed", true);
     Execution.printOutputMap(Execution.getFile("output.map"));
     throw new RuntimeException("Killed by input command");
   } else if (cmd.equals("bail")) {
     // Up to program to look at this flag and actually gracefully stop
     stderr.println("MonitorThread: BAILING OUT");
     Execution.shouldBail = true;
   } else stderr.println("Invalid command: '" + cmd + "'");
 }