Package wsh.util

Class LogMonitor

  • All Implemented Interfaces:
    Monitor

    public class LogMonitor
    extends java.lang.Object
    implements Monitor
    Report progress to default Logger
    • Constructor Summary

      Constructors 
      Constructor Description
      LogMonitor​(java.lang.String prefix, java.util.logging.Logger logger)
      Progress will be reported to this Logger.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Interrupt any further work.
      static java.lang.String getProgressReport​(long startTime, long currentTime, double fraction, double initFraction)
      Get a user-viewable String describing the progress and completion time.
      void initReport​(double initFraction)
      Initialize the fraction of the work that was completed when the process started.
      boolean isCanceled()
      If true, then any further progress should be cancelled.
      static void main​(java.lang.String[] argv)
      run tests
      void report​(double fraction)
      This method will be called with the current fraction of work done.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LogMonitor

        public LogMonitor​(java.lang.String prefix,
                          java.util.logging.Logger logger)
        Progress will be reported to this Logger.
        Parameters:
        prefix - Prefix this string to every report.
        logger - Send to this Logger. If null, then check arguments but do nothing.
    • Method Detail

      • initReport

        public void initReport​(double initFraction)
        Description copied from interface: Monitor
        Initialize the fraction of the work that was completed when the process started. If not called, then assumed to be 0.
        Specified by:
        initReport in interface Monitor
        Parameters:
        initFraction - Fraction of work done when process started, from 0 to 1.
      • report

        public void report​(double fraction)
        Description copied from interface: Monitor
        This method will be called with the current fraction of work done. Values range from 0 at the beginning to 1 when all work is done.
        Specified by:
        report in interface Monitor
        Parameters:
        fraction - Fraction of work done so far, from 0 to 1. This value must equal or exceed all values previously passed to this method or to initReport.
      • isCanceled

        public boolean isCanceled()
        Description copied from interface: Monitor
        If true, then any further progress should be cancelled.
        Specified by:
        isCanceled in interface Monitor
        Returns:
        true, when any requested work should be interrupted. False, if progress is expected to run to completion.
      • cancel

        public void cancel()
        Interrupt any further work. Causes isCancelled() to return true.
      • getProgressReport

        public static java.lang.String getProgressReport​(long startTime,
                                                         long currentTime,
                                                         double fraction,
                                                         double initFraction)
        Get a user-viewable String describing the progress and completion time.
        Parameters:
        startTime - Time in milliseconds when work began.
        currentTime - Current time in milliseconds.
        fraction - Current fraction of total progress, between 0 and 1.
        initFraction - Initial fraction of total progress, between 0 and 1, when work started.
        Returns:
        Progress report as a string.
      • main

        public static void main​(java.lang.String[] argv)
                         throws java.lang.Exception
        run tests
        Parameters:
        argv - command line
        Throws:
        java.lang.Exception - test failures