Class ProgressReportingManager

java.lang.Object
com.biglybt.ui.swt.progress.ProgressReportingManager
All Implemented Interfaces:
IProgressReportConstants

public class ProgressReportingManager extends Object implements IProgressReportConstants
A manager that aggregates and forward progress information for long running operations

This is a non-intrusive implementation, such that, it does not directly manage any of the process; it simply receives and forwards information

The primary user of this class is the MainStatusBar where it is used to display progress information

  • Field Details

    • INSTANCE

      private static ProgressReportingManager INSTANCE
    • configListenerAutoRemoveInactive

      private final ParameterListener configListenerAutoRemoveInactive
    • progressReporters

      private ProgressReporterStack progressReporters
      A custom stack to keep track of ProgressReporter
    • reporterCounter

      private int reporterCounter
      Keeps count of all ProgressReporter created since this session started; is used as unique ID and hashCode for each instance of ProgressReporter
    • COUNT_ALL

      public static final int COUNT_ALL
      See Also:
    • COUNT_ACTIVE

      public static final int COUNT_ACTIVE
      See Also:
    • COUNT_ERROR

      public static final int COUNT_ERROR
      See Also:
    • listeners

      private CopyOnWriteList listeners
      A CopyOnWriteList of IProgressReportingListener
    • isAutoRemove

      private boolean isAutoRemove
      Convenience variable tied to the parameter "auto_remove_inactive_items"
  • Constructor Details

    • ProgressReportingManager

      private ProgressReportingManager()
      Private constructor
  • Method Details

    • getInstance

      public static final ProgressReportingManager getInstance()
    • destroyInstance

      public static void destroyInstance()
    • dispose

      private void dispose()
    • addReporter

      public IProgressReporter addReporter()
    • addReporter

      public IProgressReporter addReporter(String name)
    • getReporterCount

      public int getReporterCount(int whatToCount)
      Returns the number of reporters that have sent any event to this manager and have not been removed
      • COUNT_ERROR - count all reporters in error state
      • COUNT_ACTIVE - count all reporters that are still active
      • COUNT_ALL - count all reporters
      Parameters:
      whatToCount - one of the above constants; will default to COUNT_ALL if the parameter is unrecognized
      Returns:
    • hasMultipleActive

      public boolean hasMultipleActive()
      A convenience method for quickly determining whether more than one reporter is still active. This method can be much quicker than calling #getReporterCount() and inspecting the returned value if the number of reporters is high since we may not have to go through the entire list before getting the result
      Returns:
      true if there are at least 2 active reporters; false otherwise
    • getNextActiveReporter

      public IProgressReporter getNextActiveReporter()
      Returns the next active reporter
      Returns:
      the next reporter that is still active; null if none are active or no reporters are found
    • getCurrentReporter

      public IProgressReporter getCurrentReporter()
      Returns the current reporter, in other word, the last reporter to have reported anything
      Returns:
      the last reporter; null if none are found
    • getReporters

      public List getReporters(boolean onlyActive)
      Returns a modifiable list of ProgressReporters; manipulating this list has no effect on the internal list of reporters maintained by this manager
      Parameters:
      onlyActive - true to filter the list to only include those reporters that are still active
      Returns:
      a sorted List of ProgressReporter where the oldest reporter would be at position 0
    • getReportersArray

      public IProgressReporter[] getReportersArray(boolean onlyActive)
      Returns a modifiable array of ProgressReporters; manipulating this array has no effect on the internal list of reporters maintained by this manager
      Parameters:
      onlyActive - true to filter the array to only include those reporters that are still active
      Returns:
      a sorted array of ProgressReporter where the oldest reporter would be at position 0
    • remove

      public boolean remove(IProgressReporter reporter)
      Removes the given ProgressReporter from this manager. This has the effect that any subsequent event reported by the same reporter will not be captured nor forwarded by this manager
      Parameters:
      reporter -
      Returns:
    • addListener

      public void addListener(IProgressReportingListener listener)
      Parameters:
      listener -
    • removeListener

      public void removeListener(IProgressReportingListener listener)
      Parameters:
      listener -
    • notifyListeners

      private void notifyListeners(int eventType, IProgressReporter reporter)
      Notifies listeners that the given ProgressReporter has been modified
      Parameters:
      eventType -
      reporter -
    • notifyManager

      protected void notifyManager(IProgressReporter reporter)
      Push this reporter on top of the stack, and notifies any listeners that a state change has occurred
      Parameters:
      reporter -
    • getNextAvailableID

      protected final int getNextAvailableID()
      Returns the next available ID that can be assigned to a ProgressReporter
      Returns:
      int the next available ID