ProgressMonitoring

From AardRock Wiki
Jump to navigation Jump to search

Progress Monitoring Framework

The progress monitoring framework takes care of the following:

  • Keeping track of the progress of possibly time-consuming actions (jobs).
  • Keeping track of what a job is doing through meaningful messages.
  • Indicating whether a job failed or succeeded, and how.
  • Cancelling jobs.

Usage

If you have a piece of code that is possibly time consuming and you want to provide feedback to the user while the code gets executed, wrap it in a job and call:

CheetahCore.getDefaultJobQueue().enqueue(myJob);

This puts your job in the job queue and allows the Workers to execute it. In your Job implementation of run(), call the appropriate methods on the !ProgressMonitor to provide feedback about your progress.

Original design

class Worker {
  void schedule(Job job);
  void start();
  void addProgressMonitor(ProgressMonitor monitor);
}

interface Job {
  Status run(ProgressMonitor monitor);
}

interface ProgressMonitor {
  void done();
  void setTotalWork(int amount);
  void worked(int amount);
  void setMessage(String message);
  boolean isCancelled();
  void reset();
}

class Status {
  StatusType type;
  Throwable throwable;
  String message;
}

enum StatusType {
  OK, ERROR, CANCELLED;
}


Inspired by Eclipse jobs.