public class MultiProgressMonitor
extends java.lang.Object
Output is of the format:
Task: subA: 1, subB: 75% (3/4) (-)\r Task: subA: 2, subB: 75% (3/4), subC: 1 (\)\r Task: subA: 2, subB: 100% (4/4), subC: 1 (|)\r Task: subA: 4, subB: 100% (4/4), subC: 4, done \n
Callers should try to keep task and sub-task descriptions short, since the output should fit on one terminal line. (Note that git clients do not accept terminal control characters, so true multi-line progress messages would be impossible.)
| Modifier and Type | Class and Description |
|---|---|
class |
MultiProgressMonitor.Task
Handle for a sub-task.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
UNKNOWN
Constant indicating the total work units cannot be predicted.
|
| Constructor and Description |
|---|
MultiProgressMonitor(java.io.OutputStream out,
java.lang.String taskName)
Create a new progress monitor for multiple sub-tasks.
|
MultiProgressMonitor(java.io.OutputStream out,
java.lang.String taskName,
long maxIntervalTime,
java.util.concurrent.TimeUnit maxIntervalUnit)
Create a new progress monitor for multiple sub-tasks.
|
| Modifier and Type | Method and Description |
|---|---|
MultiProgressMonitor.Task |
beginSubTask(java.lang.String subTask,
int subTaskWork)
Begin a sub-task.
|
void |
end()
End the overall task.
|
void |
waitFor(java.util.concurrent.Future<?> workerFuture)
Wait for a task managed by a
Future, with no timeout. |
void |
waitFor(java.util.concurrent.Future<?> workerFuture,
long timeoutTime,
java.util.concurrent.TimeUnit timeoutUnit)
Wait for a task managed by a
Future. |
public static final int UNKNOWN
public MultiProgressMonitor(java.io.OutputStream out,
java.lang.String taskName)
out - stream for writing progress messages.taskName - name of the overall task.public MultiProgressMonitor(java.io.OutputStream out,
java.lang.String taskName,
long maxIntervalTime,
java.util.concurrent.TimeUnit maxIntervalUnit)
out - stream for writing progress messages.taskName - name of the overall task.maxIntervalTime - maximum interval between progress messages.maxIntervalUnit - time unit for progress interval.public void waitFor(java.util.concurrent.Future<?> workerFuture)
throws java.util.concurrent.ExecutionException
Future, with no timeout.java.util.concurrent.ExecutionExceptionwaitFor(Future, long, TimeUnit)public void waitFor(java.util.concurrent.Future<?> workerFuture,
long timeoutTime,
java.util.concurrent.TimeUnit timeoutUnit)
throws java.util.concurrent.ExecutionException
Future.
Must be called from the main thread, not a worker thread. Once a
worker thread calls end(), the future has an additional
maxInterval to finish before it is forcefully cancelled and
ExecutionException is thrown.
workerFuture - a future that returns when worker threads are finished.timeoutTime - overall timeout for the task; the future is forcefully
cancelled if the task exceeds the timeout. Non-positive values indicate
no timeout.timeoutUnit - unit for overall task timeout.java.util.concurrent.ExecutionException - if this thread or a worker thread was
interrupted, the worker was cancelled, or timed out waiting for a
worker to call end().public MultiProgressMonitor.Task beginSubTask(java.lang.String subTask, int subTaskWork)
subTask - sub-task name.subTaskWork - total work units in sub-task, or UNKNOWN.public void end()
Must be called from a worker thread.