Class ProgressLogger

java.lang.Object
uk.ac.ebi.utils.runcontrol.ProgressLogger
Direct Known Subclasses:
PercentProgressLogger

public class ProgressLogger extends Object
Reports (using a logger) the progress of some process, represented by a long number. The progress-update operations in this class are thread-safe.
Author:
brandizi
Date:
22 May 2019
  • Constructor Details

    • ProgressLogger

      public ProgressLogger(String logMessageTemplate, long progressResolution)
    • ProgressLogger

      public ProgressLogger(long progressResolution)
    • ProgressLogger

      public ProgressLogger()
  • Method Details

    • reset

      public void reset()
    • update

      public void update(long newProgress)
      Updates the current progress and possibly generates a new log message, according to getProgressResolution(). The new progress should be greater than the existing one, except for the value 0, which resets the logger for a new run of items.
    • updateWithIncrement

      public void updateWithIncrement(long increment)
      Wrapper of update(long)
    • updateWithIncrement

      public void updateWithIncrement()
    • progressReport

      protected void progressReport(long oldProgress, long newProgress)
      Invoked by update(long), decides if we have to log the new progress and possibly does it. If yes, it invokes getProgressReportAction().
    • getProgressResolution

      public long getProgressResolution()
      When update(long) and similar methods increment an old value, a logging message is generated if the difference between new and old progress is >= the resolution.
    • setProgressResolution

      public void setProgressResolution(long progressResolution)
    • getLogMessageTemplate

      public String getLogMessageTemplate()
      Default "{} items processed". This is passed to the underlining logger
    • setLogMessageTemplate

      public void setLogMessageTemplate(String logMessageTemplate)
    • getLoggingLevel

      public uk.org.lidalia.slf4jext.Level getLoggingLevel()
      The logging messages are generated with this level. Default is Level.INFO.
    • setLoggingLevel

      public void setLoggingLevel(uk.org.lidalia.slf4jext.Level loggingLevel)
    • getProgress

      public long getProgress()
      The progress is updated by update(long) and similar methods.
    • setIsThreadSafe

      public void setIsThreadSafe(boolean isThreadSafe)
      Tells us that progress updates will be thread-safe, so that we don't have to manage synchronisation and its performance overhead. Default is false, this is typically used in multi-thread applications. WARNING: do I need to tell you?
    • getProgressReportAction

      public BiConsumer<Long,Long> getProgressReportAction()

      This is invoked when the progress reaches a multiple of getProgressResolution(), as per update(long) implementation. The bi-consumer receives the before and after-update progresses so far.

      The default action logs with getLogMessageTemplate() and getLoggingLevel(). Typically, you will want to use such default action and then chain yours via BiConsumer.andThen(BiConsumer) (or the other way around, whatever you prefer). BEWARE that, without such a chaining, you'll lose (replace) the logging step. Consider appendProgressReportAction(BiConsumer) instead of the regular setter.

    • setProgressReportAction

      public void setProgressReportAction(BiConsumer<Long,Long> progressReportAction)
    • appendProgressReportAction

      public void appendProgressReportAction(BiConsumer<Long,Long> progressReportAction)
      Facility to append the action to the getProgressReportAction(). This can be useful when you want to add something to the default logging action. @see getProgressReportAction()