Class TaskSignalling

  • public class TaskSignalling
    extends Object
    Utility class for a future and the underlying thread to communicate about pause and resume actions from the user, as well as reporting progress. The computing thread is supposed to regularly call yield() when it makes sense for it to pause its work if needed.
    • Constructor Detail

      • TaskSignalling

        public TaskSignalling​(long elementsToProcess)
    • Method Detail

      • pause

        public void pause()
        Instruct the computing thread to pause its work. This will only happen once the computing thread calls yield().
      • resume

        public void resume()
        Instruct the computing thread to resume its work if it was paused.
      • isPaused

        public boolean isPaused()
        Checks whether the thread is currently meant to be paused.
      • registerProgressReporter

        public void registerProgressReporter​(ProgressReporter reporter)
        Adds a progress reporter which should be notified whenever the progress of this task changes.
      • getProgress

        public int getProgress()
        Retrieves the current progress of the task.
      • yield

        public void yield()
                   throws InterruptedException
        Method to be called by the computing thread at various points when it makes sense for it to pause its work.
        InterruptedException - thrown when the waiting stopped because the thread was interrupted (meaning that the task is canceled)
      • addProcessedElements

        public void addProcessedElements​(long processedElements)
        Method to be called by the computing thread after processing a bunch of elements, so that progress is updated.
      • setFullProgress

        public void setFullProgress()
        Mark this task as fully done.
      • wrapStream

        public <T> CloseableIterator<T> wrapStream​(CloseableIterator<T> stream,
                                                   int reportBatchSize,
                                                   int reportOffset)
        Wraps a stream by updating the progress reporter when it is iterated from. It also checks if the thread should be paused after processing each element.
        Type Parameters:
        T -
        stream - the stream to wrap
        reportBatchSize - the number of elements to wait for before updating the progress object
        reportOffset - the offset at which to start in the above batch