Exemple #1
0
 /** Removes completed and cancelled jobs from the stat list. */
 @CommandArgument
 public void clean() {
   for (int i = 0; i < jobProgressStates.size(); ) {
     ProgressState state = jobProgressStates.get(i);
     if (state.isCancelled() || state.isComplete()) {
       jobProgressStates.remove(i);
     } else {
       i++;
     }
   }
 }
Exemple #2
0
 /**
  * Prints the status of the jobs running on the server.
  *
  * @param index The 1-based index of the job to print the status of, or zero to print the status
  *     of all jobs.
  */
 @CommandArgument
 public void stat(int index) {
   if (this.jobProgressStates == null) {
     System.err.println("Server not running");
     return;
   }
   if (index == 0) {
     List<ProgressState> progress = new ArrayList<ProgressState>(this.jobProgressStates);
     if (progress != null) {
       System.out.println(
           "   # Title                     Progress Status                          ");
       System.out.println(
           "------------------------------------------------------------------------");
       for (int i = 0, n = progress.size(); i < n; i++) {
         ProgressState state = progress.get(i);
         char flag = ' ';
         if (state.isComplete()) {
           flag = '*';
         } else if (state.isCancelled()) {
           flag = 'X';
         } else if (state.isCancelPending()) {
           flag = 'C';
         }
         String title = state.getTitle();
         if (title.length() > 25) {
           title = title.substring(0, 24) + ">";
         }
         String status = state.getStatus();
         if (status.length() > 32) {
           status = status.substring(0, 31) + ">";
         }
         String progStr =
             (state.isIndeterminant()
                 ? "????????"
                 : String.format(" % 6.2f%%", 100.0 * state.getProgress()));
         System.out.printf("%c% 3d %-25s %s %-33s\n", flag, i + 1, title, progStr, status);
       }
     }
   } else if (index > 0 && index <= this.jobProgressStates.size()) {
     ProgressState state = this.jobProgressStates.get(index - 1);
     System.out.printf("Job #%d", index);
     if (state.isComplete()) {
       System.out.print(" [COMPLETE]");
     } else if (state.isCancelled()) {
       System.out.print(" [CANCELLED]");
     } else if (state.isCancelPending()) {
       System.out.print(" [CANCEL PENDING]");
     }
     System.out.println();
     System.out.printf("Title    : %s\n", state.getTitle());
     if (state.isIndeterminant()) {
       System.out.print("Progress : ???");
     } else {
       System.out.printf("Progress : %.2f%%", 100.0 * state.getProgress());
     }
     int maximum = state.getMaximum();
     int value = state.getValue();
     if (maximum > 0) {
       System.out.printf(" (%d/%d)", value, maximum);
     }
     System.out.println();
     System.out.printf("Status   : %s\n", state.getStatus());
   } else {
     System.err.println("Invalid job number");
   }
 }