Class TaskSignalling
- java.lang.Object
-
- org.openrefine.runners.local.pll.util.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 callyield()
when it makes sense for it to pause its work if needed.
-
-
Constructor Summary
Constructors Constructor Description TaskSignalling(long elementsToProcess)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProcessedElements(long processedElements)
Method to be called by the computing thread after processing a bunch of elements, so that progress is updated.int
getProgress()
Retrieves the current progress of the task.boolean
isPaused()
Checks whether the thread is currently meant to be paused.void
pause()
Instruct the computing thread to pause its work.void
registerProgressReporter(ProgressReporter reporter)
Adds a progress reporter which should be notified whenever the progress of this task changes.void
resume()
Instruct the computing thread to resume its work if it was paused.void
setFullProgress()
Mark this task as fully done.<T> CloseableIterator<T>
wrapStream(CloseableIterator<T> stream, int reportBatchSize, int reportOffset)
Wraps a stream by updating the progress reporter when it is iterated from.void
yield()
Method to be called by the computing thread at various points when it makes sense for it to pause its work.
-
-
-
Method Detail
-
pause
public void pause()
Instruct the computing thread to pause its work. This will only happen once the computing thread callsyield()
.
-
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.- Throws:
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
-- Parameters:
stream
- the stream to wrapreportBatchSize
- the number of elements to wait for before updating the progress objectreportOffset
- the offset at which to start in the above batch- Returns:
-
-