Interface IProgressReporterListener

All Superinterfaces:
IProgressReportConstants
All Known Implementing Classes:
ProgressReporterPanel, ProgressReporterWindow.AutoRemoveListener

public interface IProgressReporterListener extends IProgressReportConstants
A simple listener interface used to pass a ProgressReport to a listener from a ProgressReporter
  • Method Details

    • report

      int report(IProgressReport progressReport)
      When an event is detected this callback method will be called so listeners can take appropriate action such as updating a UI element

      Currently there are 2 return types recognized:

      • RETVAL_OK - Indicates the given ProgressReport has been consumed successfully
      • RETVAL_OK_TO_DISPOSE - Indicates that this listener is no longer interested in any subsequent reports

      The return value of RETVAL_OK_TO_DISPOSE is a hint to the caller that it is now safe to remove this listener from the caller's list of listeners. This pattern allows the caller to perform clean up operations associated with this listener, and allows the listener to initiate its own removal from within an event loop.

      A typical life cycle of an event listener is create listener, register listener, then remove listener. To accomplish all three steps we would need a reference to the listeners at all time as can be seen in this sample:

       ProgressReporter reporter = new ProgressReporter("I'm a reporter");
      
       // Create a concrete listener since we need to remove it later for clean up
       IProgressReporterListener listener = new IProgressReporterListener() {
              public int report(ProgressReport progressReport) {
                      // Do some work here
                      return RETVAL_OK;
              }
       };
      
       // Add the listener
       reporter.addListener(listener);
      
       // Do some more work
      
       // Then for clean up remove the listener
       if ([some condition] == true) {
              reporter.removeListener(listener);
       }
      
       
      Sometime it is more convenient to remove a listener from within the call to .report() but a direct attempt at removal of this listener may result in modification conflict since most likely this method is being called from within an iterator loop which does not allow concurrent modifications. To address this limitation we make use of the RETVAL_OK_TO_DISPOSE as a return code which will allow the caller to perform the clean up as in this modification of the example above:
       ...
      
       final IProgressReporterListener listener = new IProgressReporterListener() {
              public int report(ProgressReport progressReport) {
      
                      // Do some work here
      
                      // This would throw a ConcurrentModificationException
                      reporter.removeListener(listener);
      
                      // This would work
                      if ([some condition] == true) {
                              return RETVAL_OK_TO_DISPOSE;
                      }
      
                      return RETVAL_OK;
              }
       };
       

      If the decision to remove a listener is based on the information contained in the given ProgressReport we can implement a much simpler listener as an inner class like so:

      
       ProgressReporter reporter = new ProgressReporter("I'm a reporter");
      
       // Creates an anonymous inner class using RETVAL_OK_TO_DISPOSE to initiate clean up
       reporter.addListener(new IProgressReporterListener() {
              public int report(ProgressReport progressReport) {
      
                      // Do some work
      
                      if ([some condition] == true) {
                              return RETVAL_OK_TO_DISPOSE;
                      }
                      return RETVAL_OK;
      
              }}
       );
      
      
       
      Parameters:
      progressReport -
      Returns: