Class ProgressMonitor

java.lang.Object
javax.security.auth.callback.TextOutputCallback
org.opends.server.tools.upgrade.ProgressMonitor
All Implemented Interfaces:
Serializable, Callback

public final class ProgressMonitor extends TextOutputCallback
A progress notification callback.

This progress monitor allows to specify the total number of units of work to be completed, and then marking them as being completed.

Sample usage 1

 
 final List<Task> tasks = ...;
 final UpgradeContext context = ...;
 final LocalizableMessage msg = ...;

 ProgressMonitor.reportProgressMonitor(upgradeContext, msg, tasks.size(), monitor -> {
     for (Task t : tasks) {
         monitor.worked(1);
     }
 });
 
 

Sample usage 2

 
 final UpgradeContext context = ...;
 final LocalizableMessage msg = ...;

 ProgressMonitor.reportProgress(upgradeContext, msg, 100, monitor -> {
     try {
         // do first task, which takes a third the of the total time
         monitor.worked(33);
         // do second task, which takes the remaining time
     } catch (final Exception e) {
         // do something else with the exception
     }
 });
 
 

Inspired by Eclipse's org.eclipse.core.runtime.SubMonitor class.

See Also:
  • Method Details

    • getProgress

      public int getProgress()
      Returns an integer which represents the task's progress percentage, i.e. the percentage of work completed. 0 means no work has been completed, while 100 means all the work has been completed, and -100 means there was an error.
      Returns:
      An integer which represents the task's progress percentage.
    • worked

      public void worked(int work) throws com.forgerock.opendj.cli.ClientException
      Marks and prints additional completed work.
      Parameters:
      work - the additional work completed
      Throws:
      com.forgerock.opendj.cli.ClientException - if the progress cannot be printed
    • complete

      public void complete() throws com.forgerock.opendj.cli.ClientException
      Marks and prints that all the work has been completed.
      Throws:
      com.forgerock.opendj.cli.ClientException - if the progress cannot be printed
    • error

      public void error() throws com.forgerock.opendj.cli.ClientException
      Marks and prints that there was an error. Once an error occurred, the progress cannot go back to a non error state.
      Throws:
      com.forgerock.opendj.cli.ClientException - if the progress cannot be printed