Package uk.ac.ebi.utils.runcontrol
Class ProgressLogger
java.lang.Object
uk.ac.ebi.utils.runcontrol.ProgressLogger
- Direct Known Subclasses:
PercentProgressLogger
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 Summary
ConstructorDescriptionProgressLogger
(long progressResolution) ProgressLogger
(String logMessageTemplate, long progressResolution) -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendProgressReportAction
(BiConsumer<Long, Long> progressReportAction) Facility to append the action to thegetProgressReportAction()
.uk.org.lidalia.slf4jext.Level
The logging messages are generated with this level.Default "{} items processed".long
The progress is updated byupdate(long)
and similar methods.This is invoked when the progress reaches a multiple ofgetProgressResolution()
, as perupdate(long)
implementation.long
Whenupdate(long)
and similar methods increment an old value, a logging message is generated if the difference between new and old progress is >= the resolution.protected void
progressReport
(long oldProgress, long newProgress) Invoked byupdate(long)
, decides if we have to log the new progress and possibly does it.void
reset()
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.void
setLoggingLevel
(uk.org.lidalia.slf4jext.Level loggingLevel) void
setLogMessageTemplate
(String logMessageTemplate) void
setProgressReportAction
(BiConsumer<Long, Long> progressReportAction) void
setProgressResolution
(long progressResolution) void
update
(long newProgress) Updates the current progress and possibly generates a new log message, according togetProgressResolution()
.void
increments
by 1void
updateWithIncrement
(long increment) Wrapper ofupdate(long)
-
Constructor Details
-
ProgressLogger
-
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 togetProgressResolution()
. 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 ofupdate(long)
-
updateWithIncrement
public void updateWithIncrement()increments
by 1 -
progressReport
protected void progressReport(long oldProgress, long newProgress) Invoked byupdate(long)
, decides if we have to log the new progress and possibly does it. If yes, it invokesgetProgressReportAction()
. -
getProgressResolution
public long getProgressResolution()Whenupdate(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
Default "{} items processed". This is passed to the underlining logger -
setLogMessageTemplate
-
getLoggingLevel
public uk.org.lidalia.slf4jext.Level getLoggingLevel()The logging messages are generated with this level. Default isLevel.INFO
. -
setLoggingLevel
public void setLoggingLevel(uk.org.lidalia.slf4jext.Level loggingLevel) -
getProgress
public long getProgress()The progress is updated byupdate(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
This is invoked when the progress reaches a multiple of
getProgressResolution()
, as perupdate(long)
implementation. The bi-consumer receives the before and after-update progresses so far.The default action logs with
getLogMessageTemplate()
andgetLoggingLevel()
. Typically, you will want to use such default action and then chain yours viaBiConsumer.andThen(BiConsumer)
(or the other way around, whatever you prefer). BEWARE that, without such a chaining, you'll lose (replace) the logging step. ConsiderappendProgressReportAction(BiConsumer)
instead of the regular setter. -
setProgressReportAction
-
appendProgressReportAction
Facility to append the action to thegetProgressReportAction()
. This can be useful when you want to add something to the default logging action. @seegetProgressReportAction()
-